整天都在这个问题上摸不着头脑.我正在尝试在MVC Identity 2.0.1中设置"非常长"的登录会话.(30天).
我使用以下cookie启动:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
SlidingExpiration = true,
ExpireTimeSpan = System.TimeSpan.FromDays(30),
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/My/Login"),
CookieName = "MyLoginCookie",
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
Run Code Online (Sandbox Code Playgroud)
总的来说,工作正常.因此,cookie设置为30天,所有看起来都很好.
如果我关闭浏览器并在"validateInterval"持续时间过去之后回来(这里30分钟)我仍然登录,但是现在cookie仅作为"会话"重新发布(仍然是正确的cookie名称)!30天的到期消失了.
如果我现在关闭浏览器/再次重新打开,我将不再登录.
我已经测试了删除"提供者"并且所有工作都按预期进行,我可以在几个小时后回来并且我仍然可以正常登录.我读到最好使用邮票重新验证,所以我不确定如何继续.