Session.Abandon() doesn't seem to do anything. You would expect the Session_end event to fire when Session.Abandon() is called.
Clearing the session will not unset the session, it still exists with the same ID for the user but with the values simply cleared. Abandon will destroy the session completely, meaning that you need to begin a new session before you can store any more values in the session for that user.
Alternatively, to deliberately end a session you can use the Session. Abandon method of the Session object. For example, you can provide a Quit button on a form with the ACTION parameter set to the URL of an .
There Are 3 ways to Destroy SessionSession. Abandon(); Session. Clear(); Session. RemoveAll();
Disable session state at the application levelIn Solution Explorer, double-click Web. config to view the contents of this file. Locate the <sessionState> section, and set the mode value to Off. Save the file and/or the project to disable session state throughout all pages in the application.
This is most likely because your SessionMode
is not InProc
(the only one that can detect when a session ends).
Quoted from MSDN:
Session Events
ASP.NET provides two events that help you manage user sessions. The Session_OnStart event is raised when a new session starts, and the Session_OnEnd event is raised when a session is abandoned or expires. Session events are specified in the Global.asax file for an ASP.NET application.
The Session_OnEnd event is not supported if the session Mode property is set to a value other than InProc, which is the default mode.
Session.Abandon() is the way to end a session. What is the problem you are encountering?
If its Back button related, that is a completely different issue ( page doesn't postback on Back, instead it runs one from clientside cache so no server side methods will execute).
Additionally, Session_End is problematic. It will only fire on Session.Abandon() when using InProc sessions, so if you are using a different Session mode, it cannot be relied on. Otherwise, Session_End will fire when SessionTimeout is reached ( default is 20 minutes I believe, configured in Web.Config ).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With