Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a logout button and in the click event I have cleared all session variables and redirected page to login page. But after logout, when I click back button, it goes to the previous page accessed. This is a very common problem several people facing but I couldn't solve it. I tried all of the below options,

session["username"] = "";
session.clear();
session.abandon();


Tried giving these in Global.ascx,
Removed the iis session timeout setting..

But none of the above is working. It again goes back to prevous page.
And I can't disable the back button in browser since my logout button is in master page. If anyone has solved this problem, please do help to come out of this problem.
Posted
Updated 23-Aug-10 22:32pm
v2

The answer to this is always the same. You need to set your pages so they are not cached. If you'd googled the problem, you'd have found any number of pages with this info on it:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

Google is a wonderful thing.
 
Share this answer
 
Comments
NishaPai 24-Aug-10 5:25am    
Thanks for the reply.. But I need to add this to all the pages I use which is not feasible when there are very lagre number of pages..
Hi,

Here is one solution, this might help you.

In Master Page Load event check if session["username"] = "" or session["username"] = null.

If so, redirect to Login Page.

if (session["username"] = "" || session["username"] = null)
{
Response.Redirect("~\Login.aspx")
}


Note: You should not use the same Master Page for Login.aspx page.
 
Share this answer
 
Comments
NishaPai 24-Aug-10 5:33am    
simple logic.. thank you very much. I have one more problem with session timeout. I have given it as 20mins but it gets timed out before that. Any idea what needs to be done for that?
NishaPai 24-Aug-10 6:00am    
In the above logic also, page goes back to previous page..
Well, Dont rely on Session.abandon. Rather than doing this you use a Session Variable and check if session variable is available in any request.

I mean :

Say when someone logs in you set
Session["IsLoggedIn"] = true;

Now for any request, check for IsLoggedIn.

When the user logs out, reset the value IsLoggedIn to false and set other variables to null.

In this way you will be absolutely sure that your user does not connect to the previous session even though Session.Abandon does not work.
 
Share this answer
 
Comments
NishaPai 24-Aug-10 5:34am    
Thank you abhishek..
you could clear your browsing history using javascript


<script language="javascript"> 
{
  var len=history.length;   
  history.go(-len); 
  window.location.href= "logout.aspx"
 }
</script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900