【问题标题】:HttpContext.Current.Session vs Context.SessionHttpContext.Current.Session 与 Context.Session
【发布时间】:2013-01-08 03:28:38
【问题描述】:

它们是一样的吗?还是它们不同?

我读过这个 SO postthis 但他们比较的是 HttpContext.Current.Session 和 Session 而不是 Context.Session。我错过了什么/误解了什么?

【问题讨论】:

  • Context.Session 是什么意思?

标签: c# asp.net


【解决方案1】:

Context.Session 在与 HttpContext.Current.Session 相同的页面中。 HttpContext.Current.Session 通常用于不直接在页面上或没有对当前页面的引用的代码。

【讨论】:

    【解决方案2】:

    HttpApplication 的 Session 属性表现出与 HttpContext.Current.Session 属性不同的行为。如果可用,它们都将返回对同一个 HttpSessionState 实例的引用。当当前请求没有可用的 HttpSessionState 实例时,它们的作用不同。

    关于这个答案,你有完整的回答:

    Difference between Session and HttpContext.Current.Session

    【讨论】:

      【解决方案3】:

      是的,它们完全一样。 Context 是页面上下文,因此它比HttpContext.Current“更大”(包含更多数据),但两者的属性 Session 具有相同的值。

      【讨论】:

        【解决方案4】:

        两者是相同的,没有区别,有时当前会话需要通过不从 Page 继承的代码访问(尽管是一种不好的做法),在这些情况下 httpcontext.current.session 非常方便并且可以访问会话.

        也调查一下: Difference between Session and HttpContext.Current.Session

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-03-31
          • 1970-01-01
          • 2011-01-31
          • 1970-01-01
          • 2016-03-10
          • 1970-01-01
          • 1970-01-01
          • 2012-04-29
          相关资源
          最近更新 更多