浙林龙哥

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
1.HttpContext.Cache
有关缓存,可以参考这篇文章:
http://www.cnblogs.com/abac/archive/2004/02/11/1166.aspx
它提到:
Asp.net中,提供了专门用于缓存数据的Cache对象,它的应用范围是应用程序域。生存期是和应用程序紧密相关的,每当应用程序启动的时候就重新创建Cache对象。它域Application对象的主要区别就是提供了专门用于缓存管理的特性,比如依赖和过期策略。
你可以使用Cache对象和它的属性来实现高级的缓存功能,同时可以利用Asp.net Cache来对客户端输出的响应内容进行缓存。

2.HttpContext.Items
参考文章:http://odetocode.com/Articles/111.aspx
它提到:
First, let’s be clear and state that what you keep in the Items collection will have a very limited scope. Anything you place into the Items collection will only be around for the duration of a single web request, unlike the Session collection, which will keep it’s contents around for each user as long as they continue to make requests. Nevertheless, we will demonstrate several useful techniques with the Items collection in this article.
HttpContext.Items的作用域是一个独立的Web请求。有关它的作用域,它举了个例子:
在页面WebForm1.aspx的Page_Load中加入:
...
Context.Items["WebForm1List"] = list;
Server.Transfer("WebForm2.aspx");

然后在WebForm2.aspx的Page_Load中加入:
ArrayList list = Context.Items["WebForm1List"] as ArrayList;
结果运行正常,但将Server.Transfer换成Response.Redirect
就不行了原因是重定向使用了新的HTTP request然后将会有新的Context而此时的Context并不是原先我们在WebForm1.aspx中放有list的Context了。


posted on 2004-06-19 14:25  浙林龙哥  阅读(2932)  评论(2编辑  收藏  举报