ASP.NET身份2记住我 - 用户被注销

Rhy*_*ens 10 c# remember-me asp.net-mvc-5 asp.net-identity-2

我在我的MVC5应用程序中使用Identity 2.1.我将PasswordSignInAsync的isPersistent属性设置为true以启用"记住我":

var result = await SignInManager.PasswordSignInAsync(model.Username, 
  model.Password, 
  true, 
  shouldLockout: false);
Run Code Online (Sandbox Code Playgroud)

但是,如果我一夜之间保持登录状态,那么当我在早上刷新页面时,它会将我退出,我必须再次登录.在用户手动注销之前,如何防止自动注销?

它与身份使用的Cookie身份验证有关吗?我真的不了解Startup.Auth.cs中设置的CookieAuthenticationOptions.

new CookieAuthenticationProvider
{  
   OnValidateIdentity = SecurityStampValidator
      .OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
      validateInterval: TimeSpan.FromMinutes(30),
      regenerateIdentity: (manager, user)
      => user.GenerateUserIdentityAsync(manager))
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*yov 13

我想你应该读这篇文章.有两种不同的间隔:ValidateIntervalExpireTimeSpan.在你的情况下,我认为你应该改变expireTimeSpan,而不是ValidateInterval.