I want destroy all sessions at one time. I have tried Session.Abondon() method but I don’t know why this is not destroying all the sessions.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can’t destroy all the sessions, you can only clear current session. You probably have to recycle the application pool to clear out all sessions.
Use HttpSessionState.Clear to clear out current session
From MSDN – HttpSessionState.Clear Method
Removes all keys and values from the session-state collection.
Call it like :
Session.Clear();
Method 2
I want destroy all sessions at one time
I’m fairly sure you can’t do this, short of recycling the application.
The currently accepted answer suggests using Session.Clear, but this only clears the current session – it is the same as Session.RemoveAll.
Why are there two methods Clear and RemoveAll that do exactly the same thing? I suspect RemoveAll is provided for backwards compatibility with the ASP Classic Session object, while Clear is the more usual method name for clearing items from a .NET Collection.
Method 3
There are three methods that can remove session
variables
Session.Clear() Session.RemoveAll() Session.Abandon()
Clear() and RemoveAll() perform the same thing: remove the session variables
but keep the current session in memory. Whereas, Abandon() ends the current
session.
Method 4
try:
Session.Contents.RemoveAll()
Method 5
Use Session.Clear() or Session.RemoveAll() Method
Session.Clear()
or
Session.RemoveAll()
Method 6
You have to use
this.Page.Session.Clear();
Abandon is for the current session only.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0