【发布时间】:2017-12-13 03:33:51
【问题描述】:
我正在开发一个使用 asp.net 身份的 asp.net mvc 应用程序。
在Startup.Auth.cs 文件中,我将ExpireTimeSpan 设置为20 天,但是当我登录到我的应用程序时,不到20 天我的应用程序就被注销了,我必须再次登录!
Startup.Auth.cs
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/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, User>(
validateInterval: TimeSpan.FromMinutes(0),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
ExpireTimeSpan = TimeSpan.FromDays(20),
SlidingExpiration = true
});
在Login 行动中:
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: true);
更新
当我登录时,会生成.AspNet.ApplicationCookie,并且它的过期日期设置为“20”天后,当我第二天打开网站时,我已经注销但 cookie 存在。
这个问题的原因是什么?
提前致谢。
【问题讨论】:
-
model.RememberMe是否设置为true并且您确定在调用PasswordSignInAsync时它是true? -
多快?
-
@CodingYoshi 是的,
RememberMe设置为true,我确定! -
@sepehr 我将
ExpireTimeSpan设置为 20 天,但我必须每天至少登录一次! -
@MajidBasirati 您是否将
machineKey添加到webConfig文件并检查它是否有效?
标签: asp.net-mvc cookies asp.net-identity