ASP.NET身份用户在30分钟后注销

时间:2014-08-01 15:27:24

标签: asp.net-mvc-5 asp.net-identity

我正在开发一款应用,但即使我在过去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中的应用程序。

1 个答案:

答案 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) 
}
相关问题