c# - 这两个 HttpContext.Current.Session 和 Session 有什么区别 - asp.net 4.0

标签 c# asp.net session session-variables httpcontext

这两段代码有什么区别。

HttpContext.Current.Session["myvariable"]
Session["myvariable"]

asp.net 4.0 和 C# 4.0

最佳答案

它们实际上相同,因为它们将访问相同的 session 数据。

您可以在代码隐藏中调用 Session 的原因是 ASP.Net 页面默认扩展 System.Web.UI.Page 类型。这有一个 Session 公共(public)属性。如果您查看 Reflector 中的代码,您会发现它只是调用 HttpContext.Current.Session 本身(通过它自己的 Context 属性)。

在其他类中,您将无权访问该属性,但您可以使用 HttpContext.Current.Session 来访问 session 数据,只要您在网络应用程序。

关于c# - 这两个 HttpContext.Current.Session 和 Session 有什么区别 - asp.net 4.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7954844/

相关文章:

angularjs - Passport session 不存在

php - 无法显示错误消息

c# - 域实体上的事件?

c# - 将网格 N*N 存储到邻接图中?位置和邻居

c# - 如何使用 Mono.ZeroConf 注册服务?

c# - 使用 Linq 从两个表中获取数据

c# - 打印适合纸张 C#

asp.net - 如何抑制图像周围的链接边框?

asp.net - 如何在 ASP.NET 中构建自定义控件?

php - session_start() 导致 IE8 中通过 PHP 下载 PDF 变得困惑