Asp.net mvc 某些浏览器中不同的ASP.NET标识cookie过期时间
我在ASP.NET Identity 2中遇到了一个奇怪的问题。我用过饼干 ASP.NET标识2中的身份验证Asp.net mvc 某些浏览器中不同的ASP.NET标识cookie过期时间,asp.net-mvc,login,asp.net-identity,expired-cookies,Asp.net Mvc,Login,Asp.net Identity,Expired Cookies,我在ASP.NET Identity 2中遇到了一个奇怪的问题。我用过饼干 ASP.NET标识2中的身份验证 app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Accou
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)
});
app.UseCookieAuthentication(新的CookieAuthenticationOptions
{
AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie,
LoginPath=新路径字符串(“/Account/Login”),
Provider=新CookieAuthenticationProvider
{
//允许应用程序在用户登录时验证安全戳。
//这是一种安全功能,在您更改密码或向帐户添加外部登录时使用。
OnValidateIdentity=SecurityStampValidator.OnValidateIdentity(
validateInterval:TimeSpan.FromMinutes(30),
regenerateIdentity:(管理器,用户)=>user.GenerateUserIdentityAsync(管理器))
},
slidengexpiration=true,
ExpireTimeSpan=时间跨度从分钟(60)
});
在某些浏览器中,除了cookie过期时间外,一切都正常。我知道我必须使用CookieAuthenticationOptions.ExpireTimespan
来设置cookie有效的时间,我将其设置为一小时(ExpireTimespan=TimeSpan.FromMinutes(60)
)。在某些浏览器中,它工作正常,但在其他一些浏览器中,它每五分钟过期一次,用户每五分钟注销一次,然后必须再次登录
如果我的项目或IIS设置中存在问题,为什么在某些浏览器中它可以正常工作而没有任何问题?我甚至检查了浏览器的版本,它们都是一样的!我甚至猜测这可能是因为这些浏览器上安装了插件,所以我卸载了该浏览器并再次安装了它!但问题仍然存在
有趣的是,在一个系统中,它在chrome上是正常的,但在IE和Firefox中问题是存在的。或者在另一台电脑上,它在Firefox上是正常的,但当Firefox更新时,问题出现了
我真的很困惑。有谁能告诉我如何解决这个问题,以及为什么它只在某些浏览器中出现?请在设置过期时间的地方添加代码cookie@User3250请参阅我的更新帖子。引用自:CookieAuthenticationOptions.ExpireTimeSpan[…]过期信息在受保护的cookie票据中,我假设您正在查看浏览器指定的默认过期时间值。实际Asp.Net过期时间是cookie值的一部分。谢谢@ckerth。但是我使用默认的Asp.Net标识设置,并且不更改浏览器指定的过期时间值。那么我应该怎么做呢?您是否验证了服务器是否使用正确的cookie进行响应(在服务器端调试响应)?如果是,则到期日期可能由客户修改或介于两者之间。我不知道你是否能在服务器端处理这些案件。如果您有权访问客户端代码,则可以在客户端上设置cookie的过期日期。