Kill session in asp.net in browser close..kill session cookie
So, I have a website where I use start and end events to track and limit open instances of our web application even on the same computer. On the unload page, I call a session enabled method called session.abandon.
This raises a session end event and clears the session variable, but unfortunately does not kill the session cookie! as a result, if other browser instances are open, there are problems because their session state just disappeared ... and much worse than that, when I open the site again when the zombie session hasn't expired yet, I get multiple session start sessions and session events on any subsequent callbacks. This happens in all browsers. since I am actually killing the session (force the cookie to expire)
source to share
FormsAuthentication.SignOut (); the authentication cookie expires but does not clear the session cookie until the timeout specified in the web.config for sessionstate. If you want to delete the session immediately, manually expire the session cookie as shown below.
var myCookie = new HttpCookie ("ASP.NET_SessionId") {Expires = DateTime.Now.AddDays (-1D)}; Response.Cookies.Add (MyCookie);
source to share