Asp.net

Back Button Problem After Logout in ASP.NET

I was facing a problem during one of my project. Actually, I was developing an E-Commerce site, in which I need to give login and logout button. I did login part easily and logout also. But problem arisen, when I pushed back button. Oh! God! Even after logout, it creates a session without login. How? I put all code behind ‘Logout’ button. But still I was facing the problem. We saw many codes, tried a lot of way to logout but still back button is not disabled.

One easy way to solve this problem is applying javascript. It would not allow a person to go back to that page. But, is it a feasible solution? NO! One would like to go back, even after logout to see something. This javascript would disable to come back. So, that is not a proper solution.

So, here I am writing the proper code, which we finally found out and happy news is that, “It really works!”. So just follow this code.

If you applying a MasterPage, then copy these codes to its page load, or copy to that page’s load, which comes after login page or comes before logout page.

Place below code in master page ‘s page load event

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoServerCaching();
HttpContext.Current.Response.Cache.SetNoStore();

Place below code on logout

Session[“Admin”] = null;
Session.Abandon();
Response.Redirect(“Login.aspx”);

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.