Monday, December 13, 2010

Browser back button issue after logout

Well, I found lot of people asking resolution to handle the browser's back button once user has logged out.

Typically, users report something like:
I am facing issue in my application's logout scenario. After the user login into website, he/she uses it(website) and when done, they do a logout, which lead them back to login page. But the problem is now, from this login page if I click the browser back button then it again takes the user back to the previous visited page as if logged in. How can I stop user to view the previous page once logged out?

So, what's the basic reason behind it? It's, browser's Cache!
Now, what can be done to handle the scenario? Surely on logout event one does clear the session. Apart from that, caching has to be handled.
One need to clear the cache such that browser has no history (this will make back/forward button in browser grayed out disabled.) Here are various ways of how one can do it:
// Code disables caching by browser. Hence the back browser button
// grayed out and could not causes the Page_Load event to fire
You can add somethin similar in form aspx if you want to place it there:
<META Http-Equiv="Cache-Control" Content="no-cache"> 
META Http-Equiv="Pragma" Content="no-cache"> <META
="Expires" Content="0">
one can clear browser history through JavaScript:
//clears browser history and redirects url
<SCRIPT LANGUAGE="javascript">
var Backlen=history.length;
window.location.href=page url
one can set this in logout event:
protected void LogOut()  
string nextpage = "Logoutt.aspx";
Response.Write("<script language="javascript">");
Response.Write(" var Backlen=history.length;");
Response.Write(" history.go(-Backlen);");
Response.Write(" window.location.href='" + nextpage + "'; ");

No comments :

Post a Comment