Asp.net mvc 为什么在asp.net identity中比ExpireTimeSpan更早注销?
我正在开发一个使用asp.net标识的asp.net mvc应用程序。Asp.net mvc 为什么在asp.net identity中比ExpireTimeSpan更早注销?,asp.net-mvc,cookies,asp.net-identity,Asp.net Mvc,Cookies,Asp.net Identity,我正在开发一个使用asp.net标识的asp.net mvc应用程序。 在Startup.Auth.cs文件中,我将ExpireTimeSpan设置为20天,但当我登录到我的应用程序时,我的应用程序在20天之前注销,我必须重新登录 Startup.Auth.cs app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.Appl
在
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
});
更新
当我登录时,会生成
.AspNet.ApplicationCookie
,其过期日期设置为“20”天后,当我第二天打开站点时,我会注销,但cookie存在
这个问题的原因是什么?提前感谢。以下是提前注销的几个原因:
- 在同一个域上有多个web应用,并且所有应用都具有相同的cookie名称(cookie名称冲突)。在这种情况下,应用程序A覆盖应用程序B的cookies
- 当
设置为0/validateInterval
时,对TimeSpan.FromMinutes(0)
的所有调用都将强制用户注销并立即重新登录,包括UpdateSecurityStamp
,UserManager.CreateAncy
,UserManager.RemovePasswordAsync
,UserManager.UpdatePassword
,UserManager.RemoveLoginAsync
,UserManager.changePhoneNumberSync/setPhoneNumberSync
,UserManager.SetEmailAsync
。这意味着如果更新用户的属性,将调用UserManager.SetEmailAsync
UpdateSecurityStamp
- 如果在服务器上更新
,它也将覆盖.NET framework
机器密钥。更改会将所有已发布的cookie标记为无效。机器密钥是用于加密和解密cookie的一组密钥。如果您在负载平衡器后面运行,则需要确保web场使用一致的
机器密钥
- 如果您在cookie中存储了太多的
,它们将变大(大于~5K),一些浏览器会拒绝它们。因此,请查看已发布cookie的大小用户声明
- 用户可以将浏览器设置为在关闭Cookie时删除Cookie(私人浏览)
型号。RememberMe
设置为true
,你确定调用PasswordSignInAsync
时它是true
吗?要快多少?CodingYoshi是的,RememberMe
设置为true
,我肯定@例如,我将ExpireTimeSpan设置为20天,但我必须每天至少登录一次@MajidBasirati您是否可以将machineKey
添加到webConfig
文件中,并检查它是否有效?
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: true);