这两段代码有什么区别。
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/