问题
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?
回答1:
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.
回答2:
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();
}
...
}
来源:https://stackoverflow.com/questions/3931331/session-clear-vs-session-removeall