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?
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.
The RemoveAll method deletes all items that have been added to the Session object's Contents collection.
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.
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(); } ... }
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