HttpContext.Current.Session 和 Session 的区别

原文地址: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 Contextproperty).


在你的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.

在其他的类中,你可能不可以直接访问system.web.ui.page的session属性,但是你能够用httpcontext.current.session来访问session数据,只要你的代码正运行在一个web应用程序的上下文中。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值