如何使用后退按钮成功登录后阻止用户返回登录页面

我正在研究MVC3应用程序,并且遇到登录安全问题。 该场景是用户使用他/她的用户名和密码登录,如果正确,他/她将被重定向到他们的主页。

但如果他们点击浏览器后退按钮,他们会回到登录页面,在我的情况下,我不想要。 它与facebook,gmail等相同,一旦用户使用他/她的凭据登录,他们只需单击浏览器的后退按钮就无法返回登录页面。

您可以使用javascript检查成功登录后您将提供的cookie。 如果cookie存在,js将检查页面加载并重定向到非登录页面。 还有其他方法可以解决这个问题: 这里

你需要使缓存和标题过期,这是我使用的:

<% HttpContext.Current.Response.Cache.SetAllowResponseInBrowserHistory(false); HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); HttpContext.Current.Response.Cache.SetValidUntilExpires(false); HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); HttpContext.Current.Response.Cache.SetNoStore(); Response.Cache.SetExpires(DateTime.Now); System.Web.HttpContext.Current.Response.AddHeader("Pragma", "no-cache"); Response.Cache.SetValidUntilExpires(true); Response.Buffer = true; Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0)); Response.Expires = 0; Response.CacheControl = "no-cache"; Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-4)); Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0)); Response.AppendHeader("Pragma", "no-cache"); Response.Cache.AppendCacheExtension("must-revalidate, proxy-revalidate, post-check=0, pre-check=0"); %>  

在页眉中添加此项,下次用户尝试返回时将请求新页面加载。

您可以尝试使用此链接禁用ASP.NET中的浏览器上的后退按钮:

使用Javascript ASP.NET禁用浏览器后退按钮