加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – ASP.NET身份2记住我 – 用户被登录

发布时间:2020-12-15 06:55:34 所属栏目:百科 来源:网络整理
导读:我在我的MVC5应用程序中使用Identity 2.1. 我将PasswordSignInAsync的isPersistent属性设置为true以启用“记住我”: var result = await SignInManager.PasswordSignInAsync(model.Username,model.Password,true,shouldLockout: false); 但是,如果我一直保
我在我的MVC5应用程序中使用Identity 2.1.
我将PasswordSignInAsync的isPersistent属性设置为true以启用“记住我”:
var result = await SignInManager.PasswordSignInAsync(model.Username,model.Password,true,shouldLockout: false);

但是,如果我一直保持登录,那么当我早上刷新页面时,它会注销我,我必须重新登录.
如何在用户手动注销之前防止自动注销?

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

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

解决方法

我想你应该读 this article.有两个不同的间隔:ValidateInterval和ExpireTimeSpan.在你的情况下,我认为你应该更改expireTimeSpan,而不是ValidateInterval.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读