我正在开发一款应用,但即使我在过去30分钟内一直活跃,我也会在30分钟后退出。
这是在ConfigureAuth方法中:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User, string>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
getUserIdCallback:(id) => id.GetUserId())
}
}
我正在localhost上测试IIS Express中的应用程序。
答案 0 :(得分:4)
将SlidingExpiration = true
添加到您正在设置的属性列表中。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User, string>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
getUserIdCallback:(id) => id.GetUserId())
},
// Add this
SlidingExpiration = true,
//Use this to customize the timeout duration if the default is too short/long
ExpireTimeSpan = TimeSpan.FromMinutes(30)
}