简体   繁体   中英

When i click on back button of the browser i still get back to back page

I have used Session.Abandon(); Session.Clear(); on Logout Button and redirected to Login page. BUT When i click on back button of the browser i still get back to back page.

Because it is fetching page from cache, you may want to disable cache for those respective page.

Some people asks for disabling back button, it is not possible to disable back button. Alternatives are:

  • Prevent Caching those page
  • Prevent User from going back once user logs out of application.

For second case, check out the below code and put it in your login page.

<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>

and Call it like below:

<body onload="changeHashOnLoad(); ">
 //---Rest of your code

It will work in all the browser.

Source: SO (don't have link to the original thread)

You can use use like follows

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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