注销后C#ASP.NET MVC后退按钮问题

时间:2018-02-23 08:51:47

标签: c# asp.net model-view-controller logout back-button

我正在研究MVC应用程序的注销方法,但我遇到了一个问题。 每次我注销时,应用程序都会检查用户身份验证并将其返回到登录页面。

退出方法:

[HttpGet]
    [CustomAuthorize]
    public ActionResult Logout()
    {            
        //Response.Cache.SetExpires(DateTime.Now);
        FormsAuthentication.SignOut();
        Session.Clear();
        Session.Abandon();
        Session.RemoveAll();
        return RedirectToAction("Index", "Home");
    }

登录后使用的页面都具有[CustomAuthorize]属性。

使用MS Edge浏览器,如果单击“返回”按钮,程序将通过CustomAuthorize方法,如果用户已注销,则只会按预期将它们返回到“登录”页面。

但是,如果我使用任何其他浏览器(Chrome,Firefox),按“返回”按钮只会返回上一页,我按下了“注销”按钮,甚至没有通过CustomAuthorize来检查授权。

这可能是什么原因以及可能解决此问题的可能解决方案?

如果需要更多信息,请告诉我。

谢谢。

Justas

1 个答案:

答案 0 :(得分:0)

您需要全局禁用缓存

protected void Application_BeginRequest()
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
        Response.Cache.SetNoStore();
    }