views:

73

answers:

2

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, right? Thanks.

+5  A: 

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

    ...
}
Darin Dimitrov
nice explanation............
Nishant
+1  A: 

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.

Etienne
Note: Clear and RemoveAll just remove all entries (the user keeps the same SessionId); Abandon ends the entire session (the user gets a new SessionId).
Hans Kesting