繁体   English   中英

防止用户在asp.net mvc中注销后返回

[英]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.AllCach‌​es);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM