1

Session.Abandon(); Session.Clear();在注销按钮上使用并重定向到登录页面。但是当我点击浏览器的后退按钮时,我仍然返回到后页。

4

2 回答 2

1

因为它正在从缓存中获取页面,所以您可能希望禁用相应页面的缓存。

有些人要求禁用后退按钮,无法禁用后退按钮。替代方案是:

  • 防止缓存那些页面
  • 一旦用户退出应用程序,防止用户返回。

对于第二种情况,请查看以下代码并将其放入您的登录页面。

<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(没有指向原始线程的链接)

于 2013-03-30T10:34:18.443 回答
0

你可以使用如下

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();
于 2013-03-30T10:36:26.457 回答