c# - Session.Clear() 与 Session.RemoveAll()

标签 c# asp.net session-state

Session.Clear()Session.RemoveAll() 有区别吗?

描述和文档页面似乎说的完全一样,但是 我假设创建两个函数一定有某种原因,对吗?

最佳答案

它们完全相同。 RemoveAll 在内部调用 Clear。来自反射器:

public sealed class HttpSessionState : ICollection, IEnumerable
{
    ...

    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public void RemoveAll()
    {
        this.Clear();
    }

    ...
}

关于c# - Session.Clear() 与 Session.RemoveAll(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3931331/

相关文章:

asp.net - css 不在回发时加载

asp.net - 在 SQLServer 作为 sessionState 模式的 ASP.NET 中,如何处理 session 对象超时?

.NET HttpSessionState 不区分大小写

c# - 相同的 DbContext 在解决方案的不同项目下表现不同

c# - 对于在 WPF 中构建这样的控件,您有何建议?

c# - Javascript 确认对话框 - 防止事件处理程序触发?

Asp.Net如何将 session 状态传输到状态服务器

c# - 具有重复调用的 WCF channel 生命周期

c# - ASP.NET GridView 删除 'Input string was not in a correct format'

c# - 如何从 Excel 中解析 "cut n paste"