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.
You should use Session. Abandon() instead of removeAll if you really need to end the current session as RemoveAll() or Clear() just clears the Session variables (objects stored in Session) but the Session identifier is still alive and new variables can be added to it.
Remove Method in ASP is used to remove an item from Session Contents collection. It is a predefined method of the Session type Object. Parameter Values: It contains the value i.e name which represents the index of the specified items that would be removed from the Session.
Session. Clear() just removes all values.
There Are 3 ways to Destroy SessionSession. Abandon(); Session. Clear(); Session. RemoveAll();
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();
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.
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