如何解决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});
}
解决方法
将ExpiresUtc添加到AuthenticationProperties可以正常工作
var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
authenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant(
new ClaimsPrincipal(identity),new AuthenticationProperties {IsPersistent = IsPersistent,ExpiresUtc = identity.GetExpiresAt()}
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。