问题描述
我一辈子都无法弄清楚为什么我的应用程序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});
}
解决方法
将ExpiresUtc添加到AuthenticationProperties可以正常工作
var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
authenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant(
new ClaimsPrincipal(identity),new AuthenticationProperties {IsPersistent = IsPersistent,ExpiresUtc = identity.GetExpiresAt()}
);