什么是这两个HttpContext.Current.Session和会话之间的区别 - asp.net 4.0 [英] What is the difference between these two HttpContext.Current.Session and Session - asp.net 4.0
问题描述
什么是这2件codeS之间的区别。
What is the difference between these 2 piece of codes.
HttpContext.Current.Session["myvariable"]
Session["myvariable"]
asp.net 4.0和C#4.0
asp.net 4.0 and C# 4.0
推荐答案
他们的有效的一样,在他们将访问相同的会话数据。
They're effectively the same, in that they will access the same Session data.
您可以在$ C $叫会话
C-背后的原因是因为ASP.Net页面默认情况下延长的System.Web。 UI.Page
键入。这有一个会话
公共财产。如果你看一下code这在反射器,你可以看到,它只是调用 HttpContext.Current.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).
在其他类,你将无法获得该财产,但你可以使用 HttpContext.Current.Session
来访问会话数据,而不是,只要你在Web应用程序的上下文中运行。
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.
这篇关于什么是这两个HttpContext.Current.Session和会话之间的区别 - asp.net 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!