Microsoft Owin CookieAuthenticationOptions SlidingExpiration =假到期仍在更新

问题描述

我一辈子都无法弄清楚为什么我的应用程序cookie过期会在我将滑动值设置为false时每个请求增加到现在+15分钟。

我也正在对此电话进行索偿。

app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,SlidingExpiration = false,ExpireTimeSpan = TimeSpan.FromMinutes(15)
});
 public static void UpdateClaim(this IIdentity identity,Claim claim)
        {
            var claimsIdentity = identity as ClaimsIdentity;

            identity.RemoveClaim(claim.Type);

            claimsIdentity?.AddClaim(claim);

            var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
            authenticationManager.AuthenticationResponseGrant =
                new AuthenticationResponseGrant(new ClaimsPrincipal(identity),new AuthenticationProperties {IsPersistent = IsPersistent});
        }

enter image description here

enter image description here

解决方法

将ExpiresUtc添加到AuthenticationProperties可以正常工作

var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;

authenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant(
    new ClaimsPrincipal(identity),new AuthenticationProperties {IsPersistent = IsPersistent,ExpiresUtc = identity.GetExpiresAt()}
);

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...