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

我只是一个虾纸丫 提交于 2019-12-09 07:26:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!