Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session.Clear() vs. Session.RemoveAll()

Is there a difference between Session.Clear() and Session.RemoveAll()?

The descriptions and documentation pages seem to say exactly the same thing, but I am assuming there must be some reason for creating two functions, am I right?

like image 399
Nishant Kumar Avatar asked Oct 14 '10 08:10

Nishant Kumar


People also ask

What is the difference between Session clear and Session abandon?

Clearing the session will not unset the session, it still exists with the same ID for the user but with the values simply cleared. Abandon will destroy the session completely, meaning that you need to begin a new session before you can store any more values in the session for that user.

Which method will remove all sessions?

The RemoveAll method deletes all items that have been added to the Session object's Contents collection.

What is Session abandon ()?

The Abandon method destroys all the objects stored in a Session object and releases their resources. If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.


1 Answers

They are absolutely the same. RemoveAll calls Clear internally. From Reflector:

public sealed class HttpSessionState : ICollection, IEnumerable {     ...      [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]     public void RemoveAll()     {         this.Clear();     }      ... } 
like image 196
Darin Dimitrov Avatar answered Oct 09 '22 06:10

Darin Dimitrov