我在 ASP.NET Identity 2 中遇到了一个奇怪的问题。我在 ASP.NET Identity 2 中使用了 Cookie 身份验证。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/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, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
SlidingExpiration = true,
ExpireTimeSpan = TimeSpan.FromMinutes(60)
});
除了某些浏览器中的 cookie 过期时间外,一切都很好。我知道我必须使用CookieAuthenticationOptions.ExpireTimespan
设置 cookie 的有效时间并将其设置为一个小时 ( ExpireTimeSpan = TimeSpan.FromMinutes(60)
)。在某些浏览器中它可以正常工作,但在其他一些浏览器中,它每五分钟过期一次,用户注销并必须每 5 分钟重新登录一次!
如果这是我的项目或 IIS 设置中的问题,为什么在某些浏览器中它可以正常工作而没有任何问题?我什至检查了浏览器的版本,它们是一样的!我什至猜到可能是因为那些浏览器上安装了一个插件,所以我卸载了那个浏览器并重新安装了它!但问题仍然存在。
有趣的一点是,在一个系统中,它在 chrome 上是可以的,但在 IE 和 Firefox 中却存在问题。或者在另一台计算机上它在 Firefox 上是可以的,但是当 Firefox 更新时问题出现了!
我真的很困惑。谁能告诉我如何解决这个问题以及为什么它只在某些浏览器中出现?