在 asp.net mvc 中防止用户在注销后返回
Prevent user to go back after logout in asp.net mvc
我已经尝试了所有可能的方法来防止用户在注销后返回。但是 none 起作用了。我试过了 -
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");
}
我已经尝试了所有可能的方法来防止用户在注销后返回。但是 none 起作用了。我试过了 -
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");
}