我使用ClaimsIdentity Framework在我的一个应用程序中设置了auth。
我将这些行添加到web.config文件中,如本问题中所述。
<sessionState
mode="InProc"
timeout="1" />
我让应用程序运行一整夜,但是我仍然登录。我想将会话超时设置为30分钟,有什么建议吗?
ASP.NET MVC版本:5.2.3.0
根据ASP.Net-Identity-Cookie-Authentication-Timeouts,您应该使用Identity的UseCookieAuthentication()
参数来设置超时。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(15),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
},
SlidingExpiration = false,
ExpireTimeSpan = TimeSpan.FromMinutes(30)
});
CookieAuthenticationOptions.ExpireTimespan是允许您设置发出的cookie有效期的选项。在上面的示例中,cookie从创建之日起有效期为30分钟。30分钟过后,用户将不得不重新登录,因为SlidingExpiration设置为false。
如果将SlidingExpiration设置为true,则将在ExpireTimeSpan中途对任何请求重新发出cookie。例如,如果用户登录并在16分钟后发出第二个请求,则该cookie将在另外30分钟内重新发出。如果用户登录,然后在31分钟后发出第二个请求,则系统将提示用户登录。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句