how to Destroy all sessions at one Time in asp.net?

Deadly 提交于 2019-11-27 02:37:58

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!