Well, I found a lot of people asking for a 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 leads 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 from viewing 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 needs 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:
You can add something 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 Http-Equiv="Expires" Content="0">
one can set this in logout event:
protected void LogOut()
string nextpage = "Logoutt.aspx";
Response.Write(" var Backlen=history.length;");
Response.Write(" window.location.href='" + nextpage + "'; ");
some other combination of the above options.
] suggested, I would like to add here itself as a part of the Tip/Trick that I would not suggest to use it and mess with browser's history as this is a bad, bad thing.
One should implement it, only if they really need it and are prepared to accept that it is not a good practice.
Lastly, this would not work if one disables