ASP.NET Identity 2记住我-用户正在注销 [英] ASP.NET Identity 2 Remember Me - User Is Being Logged Out

查看:76
本文介绍了ASP.NET Identity 2记住我-用户正在注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Identity 2.1 in my MVC5 app. I am setting the isPersistent property of the PasswordSignInAsync to true to enable 'Remember Me':

var result = await SignInManager.PasswordSignInAsync(model.Username, 
  model.Password, 
  true, 
  shouldLockout: false);

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

But if I stay logged in overnight, then when I refresh the page in the morning, it logs me out and I have to sign in again. How do I prevent automatic logging out until the user manually logs out?

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

Is it something to do with the Cookie Authentication that identity uses? I don't really understand the CookieAuthenticationOptions that are set in Startup.Auth.cs.

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

推荐答案

我认为您应该阅读本文.有两个不同的时间间隔:ValidateIntervalExpireTimeSpan.在您的情况下,我认为您应该更改expireTimeSpan而不是ValidateInterval.

I think you should read this article . There are two different intervals: ValidateInterval and ExpireTimeSpan. And in your case i think you should change the expireTimeSpan, not the ValidateInterval.

这篇关于ASP.NET Identity 2记住我-用户正在注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆