ClaimsIdentity的到期时间短于定义的时间

时间:2018-04-06 11:08:29

标签: c# owin claims-based-identity

我在我的网站上使用ClaimsIdentity来识别我的用户。

我已将ExpireTimeSpan设置为一小时,但实际上它会在约15分钟后到期。我不明白为什么......

web.config:

<appSettings>
  <add key="owin:AppStartup" value="Web.AppStart" />
</appSettings>

AppStart:

public void Configuration(IAppBuilder builder)
{
    builder.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        AuthenticationMode = AuthenticationMode.Active,
        ExpireTimeSpan = TimeSpan.FromMinutes(60),
        SlidingExpiration = true,
        LogoutPath = new PathString("/Account/LogOff"),               
        LoginPath = new PathString("/Account/Login")
    });
}

用户身份验证:

internal static void SetCurrentUSer(UserModel user, HttpContextBase context)
{
    IList<Claim> claims = new List<Claim>
    {
        new Claim(ClaimTypes.NameIdentifier, user.Login),
        new Claim(ClaimTypes.UserData, JsonConvert.SerializeObject(user)),
        new Claim(ClaimTypes.Role, user.IsAdministrator ? nameof(Profiles.Administrator) : nameof(Profiles.Player))
    };

    context.GetOwinContext().Authentication.SignIn(new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie));
}

一切正常,ClaimsPrincipal也设置好,但过期时间不会超过一小时。

编辑:我忘了说我使用asp.net MVC

0 个答案:

没有答案