看看下面的代码,为一个Cache类型的变量赋值:

            HttpContext context = HttpContext.Current;
            
if(context != null)
            {
                _cache 
= context.Cache;
            }
            
else
            {
                _cache 
= HttpRuntime.Cache;
            }

那么HttpRuntime和HttpContext到底有什么区别那?

[解决方法]

1. HttpContext.Cache 属性

  为当前 HTTP 请求获取 Cache 对象

2. HttpRuntime.Cache 属性

   获取当前应用程序的 Cache。

可以看出,前者是针对一次HttpRequest,后者是针对整个应用程序
posted on 2006-03-22 17:24  今夜太冷  阅读(532)  评论(0)    收藏  举报