【发布时间】:2013-01-08 03:28:38
【问题描述】:
它们是一样的吗?还是它们不同?
我读过这个 SO post 和 this 但他们比较的是 HttpContext.Current.Session 和 Session 而不是 Context.Session。我错过了什么/误解了什么?
【问题讨论】:
-
Context.Session是什么意思?
它们是一样的吗?还是它们不同?
我读过这个 SO post 和 this 但他们比较的是 HttpContext.Current.Session 和 Session 而不是 Context.Session。我错过了什么/误解了什么?
【问题讨论】:
Context.Session 是什么意思?
Context.Session 在与 HttpContext.Current.Session 相同的页面中。 HttpContext.Current.Session 通常用于不直接在页面上或没有对当前页面的引用的代码。
【讨论】:
HttpApplication 的 Session 属性表现出与 HttpContext.Current.Session 属性不同的行为。如果可用,它们都将返回对同一个 HttpSessionState 实例的引用。当当前请求没有可用的 HttpSessionState 实例时,它们的作用不同。
关于这个答案,你有完整的回答:
【讨论】:
是的,它们完全一样。 Context 是页面上下文,因此它比HttpContext.Current“更大”(包含更多数据),但两者的属性 Session 具有相同的值。
【讨论】:
两者是相同的,没有区别,有时当前会话需要通过不从 Page 继承的代码访问(尽管是一种不好的做法),在这些情况下 httpcontext.current.session 非常方便并且可以访问会话.
也调查一下: Difference between Session and HttpContext.Current.Session
【讨论】: