Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 589
Ram Avatar asked Aug 29 '12 06:08

Ram


People also ask

How do I delete all 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.

Which method is used to remove session in asp net?

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.

What does session Clear () do?

Session. Clear() just removes all values.

How can destroy session in ASP NET MVC?

There Are 3 ways to Destroy SessionSession. Abandon(); Session. Clear(); Session. RemoveAll();


2 Answers

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();
like image 129
Habib Avatar answered Sep 22 '22 03:09

Habib


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.

like image 32
Joe Avatar answered Sep 22 '22 03:09

Joe