【Addtional】关于ForumContext

       这几天,关于HttpContext的东西没有少查资料。一直都很迷惑。难道Items集合可以Get & Set  Object !
HttpContext.Current.Items集合属性,不是用来存储字符串的吗?找遍国内的一些资料,也没有一个好的解释,MSDN上写的也很含混其辞。于是,改用Google搜索。终于一篇佳作被狗到了。

应该来说,下面一段是最能解我之惑的东西。

One property of the HttpContext object that not many ASP.NET developers know about is the Items property, which is a Hashtable for storing and retrieving information on a per-request basis. That is, the various objects that participate in an ASP.NET request - the ASP.NET Web page, User Controls, custom compiled controls, HTTP modules, and class libraries used during the page request - all have access to the HttpContext object and therefore can all read from and write to the Items Hashtable. This Hashtable, then, proves useful as a centralized data store that lasts only the length of the request that all participants involved in the request can access.

E文水平有限,就不献丑了。

从上面可以看出,只要是参与了Request请求的各种对象,包括Web页,用户控件,自定义控件,Http Modules,Request期间的类库都可以存储到Items键值对中。

详细信息请浏览:http://aspnet.4guysfromrolla.com/articles/060904-1.aspx

另:
  要实现预请求缓存,用Asp.net 的HttpContext类,HttpContext类的实例在每一个请求中创建,在请求期间的任何地方都可以通过HttpContext.Current属性访问。HttpContext类有一个Items集合属性,在请求期间所有的对象和数据都被添加到这个集合中缓存起来。和你用Cache缓存访问频率高数据一样,你可以用HttpContext.Items缓存那些每个请求都要用到的基础数据。它背后的逻辑很简单:我们向HttpContext.Items中添加一个数据,然后再从它里面读出数据。

好了,这下子再也不迷糊了!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值