【发布时间】:2015-11-04 04:24:59
【问题描述】:
所以我有一个 MVC5 Web 应用程序,并且我正在使用内置的 ASP.Identity 框架进行身份验证。我想让我的用户将其登录状态保持 30 天。
这是我在Startup.Auth.cs 中的代码:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
CookieName = "Test",
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromDays(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
ExpireTimeSpan = TimeSpan.FromDays(30)
});
我在登录后检查了 cookie,确实有效期为 30 天,但几分钟/几小时后,当我再次尝试访问该站点时,登录状态消失了。知道为什么吗?
【问题讨论】:
-
您的用户在数据库的
SecurityStamp字段中是否有任何值?
标签: c# asp.net-mvc asp.net-mvc-5 asp.net-identity