Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back arrow after signing out

I have an ASP.NET application using Forms Authentication. When the user clicks the Sign Out button on the page it runs the following code.

        FormsAuthentication.SignOut();
        Response.Expires = 0;
        Response.Cache.SetNoStore();
        Response.AppendHeader("Pragma", "no-cache");

However the user can still just press the back arrow and see the previous page without needing to log in again. I am sure it has something to do with the previous page being cached. How can I make sure they are prompted to log in again with going back?

like image 848
Craig Avatar asked Feb 23 '09 21:02

Craig


People also ask

Why after logout clicking back button on the page displays previous page content?

It happens because your browser cached the page on the client. The solution is to prevent the caching of that page(s), by forcing the browser to request a new page even when pressing Back button, instead of reading the saved one.

How do I stop PHP from going back after logout?

As you mentioned, on logout, simply unset the logged_in session variable, and destroy the session: <? php unset($_SESSION['logged_in']); session_destroy(); ?> If the user clicks back now, no logged_in session variable will be available, and the page will not load.

How do I turn off back in Javascript?

onload = function () { noBackPlease(); // Disables backspace on page except on input fields and textarea..


2 Answers

Response.Cache.SetCacheability(HttpCacheability.NoCache);
like image 118
mmx Avatar answered Sep 28 '22 13:09

mmx


And now you know why you get the message, "You've been logged out. Please close this browser window for security reasons."

No cache is a workaround.

The penultimate workaround is to use ajax to pull any sensitive information down - this would be run again in the back case, and the information should not be cached. It's more connections and more latency, but due to modern browser caching there's not much that can be done except workarounds such as these.

-Adam

like image 23
Adam Davis Avatar answered Sep 28 '22 12:09

Adam Davis