我已經寫了下面的代碼像下面刷新用戶角色後,他們訂閱我的網站像下面的具體時間到期: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