我已经写了下面的代码像下面刷新用户角色后,他们订阅我的网站像下面的具体时间到期:Asp.NET身份设置永久性Cookie后
private void RefreshUserRoles()
{
var AuthenticationManager = HttpContext.GetOwinContext().Authentication;
var Identity = new ClaimsIdentity(User.Identity);
Identity.RemoveClaim(Identity.FindFirst(ClaimTypes.Role));
Identity.AddClaim(new Claim(ClaimTypes.Role, "Subscriber"));
AuthenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant
(new ClaimsPrincipal(Identity), new AuthenticationProperties { IsPersistent = true});
}
请注意,这行代码:
AuthenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant
(new ClaimsPrincipal(Identity), new AuthenticationProperties { IsPersistent = true});
}
用户回到我的网站后,我设置cookie为持久性的,但我忘了设置此cookie的到期日期。我应该将这个cookie设置为持续30分钟,之后应该要求用户重新登录系统。
由于有些用户从不重新登录网站,这给我留下了一个问题,现在我需要在访问网站时重置其浏览器中的所有用户cookie,并在取消订阅时更改其角色。我注意到一些用户取消了他们的订阅,从来没有重新记录,但尚未他们仍然能在我的网站使用功能...
所以我的问题是:
1. How to set expiration of cookie to 30 minutes after which user will be asked to re-log onto the system.
2. How to Setup to re-check users cookies if they haven't expired in a long time so that I can reset their cookies to regular user if they cancelled subscription?
您是否确定它是cookie,并且在让它们访问这些功能之前不检查身份验证? – BillRuhl
@BillRuhl是100%,我设置了登录时的支票,检查PayPal上的订阅个人资料的状态是否有效,暂停或取消......但问题是,我发现一些用户从未从应用程序注销过很多),这个cookie留在他们的浏览器永不过期,他们取消了他们的订阅,如果他们从不重新登录,他们在我网站上的订阅基本上永远不会过期... – User987
我不知道是否可以强制通过mvc应用程序迫使每个人的cookies访问到网站后过期...这将立即解决我的问题 – User987