问题
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.
回答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();
回答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.
回答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.
回答4:
try:
Session.Contents.RemoveAll()
回答5:
Use Session.Clear() or Session.RemoveAll() Method
Session.Clear()
or
Session.RemoveAll()
回答6:
You have to use
this.Page.Session.Clear();
Abandon is for the current session only.
来源:https://stackoverflow.com/questions/12172268/how-to-destroy-all-sessions-at-one-time-in-asp-net