![](/img/trans.png)
[英]How to prevent user to click on the back button after logout in asp.net mvc with cache enabled
[英]Prevent user to go back after logout in asp.net mvc
我嘗試了所有可能的方法來防止用戶注銷后返回。 但是沒有一個有效。 我試過了 -
Response.ClearHeaders();
Response.Cache.SetAllowResponseInBrowserHistory(false);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
Response.AppendHeader("Cache-Control", "no-cache");
Response.AppendHeader("Cache-Control", "private");
Response.AppendHeader("Cache-Control", "no-store");
Response.AppendHeader("Cache-Control", "must-revalidate");
Response.AppendHeader("Cache-Control", "max-stale=0");
Response.AppendHeader("Cache-Control", "post-check=0");
Response.AppendHeader("Cache-Control", "pre-check=0");
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Expires", "Mon, 26 Jul 2000 05:00:00 GMT");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.AppendCacheExtension("no-store, must-revalidate");
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Expires", "0");
我在Chrome(v.56)上進行了測試。 上面的代碼無法阻止用戶注銷后返回。
任何想法??
轉到Global.asax.cs文件,並使用以下給出的代碼清除應用程序中的緩存(希望獲得此幫助)-
protected void Application_BeginRequest()
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
}
將此代碼行粘貼到要防止其返回的控制器上方
[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
喜歡
[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult Logout()
{
FormsAuthentication.SignOut();
Session["Username"] = null;
Session.RemoveAll();
Session.Abandon();
return RedirectToAction("Index", "Login");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.