如何使用Identity和Owin登录并坚持使用ASP.NET?

问题描述

我正在尝试使用Identity和Owin登录用户,然后在会话结束后保持登录状态。用户数据存储在SQL Server中。当我在调试器中运行它时,它似乎正在工作。

问题是:,当我将其发布到远程站点时,我可以登录,但在大约5分钟后用户不再登录。我认为这是由于会话即将到期。正在使用我的startup.cs中设置的正确到期时间创建cookie。我正在使用授权部分来拒绝用户访问该网站。我以为我只需要使用登录方法进行更改,但似乎无法在线找到丢失的内容(主要是因为我并不真正知道要搜索的内容)。 / p>

这就是我登录用户的方式

protected void SignIn(object sender,EventArgs e)
        {
            var userStore = new UserStore<IdentityUser>();
            var userManager = new UserManager<IdentityUser>(userStore);
            var user = userManager.Find(uname.Text,pwd.Text);

            if (user != null)
            {
                var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                var userIdentity = userManager.CreateIdentity(user,DefaultAuthenticationTypes.ApplicationCookie);                

                authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = true,AllowRefresh = true },userIdentity);

                Response.Redirect("~/Main.aspx");
            }
            else
            {
                errorlbl.Text = "Invalid username or password.";
            }
        }

我的startup.cs

public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // For more information on how to configure your application,visit https://go.microsoft.com/fwlink/?LinkID=316888
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,ExpireTimeSpan = TimeSpan.FromDays(14),CookieName = "MyCookieName",LoginPath = new PathString("/Login.aspx/")
            });

        }
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...