原文地址:http://stackoverflow.com/questions/7954844/what-is-the-difference-between-these-two-httpcontext-current-session-and-session
What is the difference between these two HttpContext.Current.Session and Session - asp.net 4.0
They're effectively the same, in that they will access the same Session data.
他们具有相同的作用,他们将会访问相同的session数据。
The reason you can call Session
in your code-behind is because ASP.Net pages by default extend the System.Web.UI.Page
type. This has a Session
public PRoperty. If you look at the code for this in Reflector you can see that it just calls HttpContext.Current.Session
itself (through its own Context
property).
在你的code-behind代码中之所以能够调用session,是因为Asp.net的页面默认是继承自system.web.ui.page类型的。这个类型有一个名字为session的公共属性。如果你在Reflector反编译软件中查看这个公共属性的代码,你会看到这个属性自己仅仅是调用的httpcontext.current.session而已。(在他自己的 Context属性中也全部是这样使用的)
In other classes you will not have access to that property, but you can use HttpContext.Current.Session
to access the session data instead, as long as you're running in the context of a web application.
新闻热点
疑难解答