当我点击浏览器的后退按钮时,我仍然会回到后退页面
本文关键字:按钮 浏览器 | 更新日期: 2023-09-27 18:06:40
我在注销按钮上使用Session.Abandon();
Session.Clear();
并重定向到登录页面。但当我点击浏览器的后退按钮时,我仍然会回到后退页面。
因为它是从缓存中抓取页面,你可能想要禁用那些相应页面的缓存。
有些人要求禁用后退按钮,这是不可能禁用后退按钮。替代方案是:
- 防止缓存这些页面
- 一旦用户退出应用程序,阻止用户返回。
对于第二种情况,查看下面的代码并将其放在您的登录页面中。
<script type = "text/javascript" >
function changeHashOnLoad() {
window.location.href += "#";
setTimeout("changeHashAgain()", "50");
}
function changeHashAgain() {
window.location.href += "1";
}
var storedHash = window.location.hash;
window.setInterval(function () {
if (window.location.hash != storedHash) {
window.location.hash = storedHash;
}
}, 50);
</script>
,如下所示:
<body onload="changeHashOnLoad(); ">
//---Rest of your code
它将在所有浏览器中工作。
来源:SO(没有链接到原始线程)
你可以像这样使用use
FormsAuthentication.SignOut();
Session.Abandon();
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
// clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
cookie2.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie2);
FormsAuthentication.RedirectToLoginPage();