Friday, December 26, 2008

ASP.NET 2.0 does not clear Session on Logout

Web application logout process does not clear Session properly


Situations :
Session to maintain the login and logout process. Everything is running perfect and smooth. The thing i want to know and clear is that, i want to clear system cache or web cache on log out. Actually some of the Session enabled pages opens once after logging out on the systems that are on LAN and using as Linux SQUID server on the backend. The copy of the page is stored in the cache, and opens the page without asking to log in if opened directly from the address bar. Once refreshed, the page then moves to Login page. Is there anyway to solve this?

After I logout and kill session in my web application, In internet explorer 6.0 user copy url and paste url and show web site like he login. I think because of internet explorer buffer in firebox 3.0 it don’t be how can we solve it on internet explore 6 ? How can we cancel internet explorer buffer cache?


Problem:
Midway through the project, I noticed that this Session information was not clearing itself when a user logged out of the system. I confirmed by logging in as "User 1", setting the Session value via a search, logging out, and subsequently logggin in as "User 2." User 2 was able to view the search criteria
entered by User 1 -- definitely NOT a desired behaviour.


Cause:
Does not clear Session when a Logout occurs. The control does perform a FormsAuthentication.Signout(), and it clears the Response with a status code of
200. But, it does not clear Session.


Solution:
The fix was simple. Use below code to fix the issue
font color="#003366">
protected void logout()
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Session.Clear();
FormsAuthentication.SignOut();
DisableBufferingOnPage()
}

protected void DisableBufferingOnPage()
{
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); // set expiry date in the
past
Response.Expires = 0;
Response.CacheControl = "no-cache";
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
}


16 comments:

  1. Hi all, I have same, is any one solved the issue using above solution ?

    ReplyDelete
  2. Nooooooooooooooo

    ReplyDelete
  3. Wow, Fantastic Blog, it’s so helpful to me, and your blog is very good,
    I’ve learned a lot from your blog here, Keep on going, my friend, I will keep an eye on it,

    ReplyDelete
  4. This posting is beautifully explained regards the topic and thanks to u for posting this information and the way it explain clearly is so nice. Hopefully it must be very necessay for people and help them......

    ReplyDelete
  5. Great Post... Works great

    ReplyDelete