Nishant Kumar
Nishant Kumar

Reputation: 6083

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?

Upvotes: 46

Views: 66669

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038810

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();
    }

    ...
}

Upvotes: 129

Etienne
Etienne

Reputation: 7201

To be save you can always just call them all like so....

Session.Clear()
Session.Abandon()
Session.RemoveAll()

VB.NET example, I am sure all you need to do is place the ; at the end of each of them. This did the trick for me as I had some problems with my Session before where they were not removed.

Upvotes: -7

Related Questions