小编pio*_*rsz的帖子

如何强制HttpWebRequest在ASP.NET环境中使用缓存?

在我的ASP.NET应用程序中,我使用HttpWebRequest来获取我想要缓存的外部资源.请考虑以下代码:

var req = WebRequest.Create("http://google.com/");
req.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable);
var resp = req.GetResponse();
Console.WriteLine(resp.IsFromCache);
var answ = (new StreamReader(resp.GetResponseStream())).ReadToEnd();
Console.WriteLine(answ.Length);
Run Code Online (Sandbox Code Playgroud)

HttpWebRequest使用IE缓存,因此当我以普通用户身份运行它时(在微型cmd测试应用程序中),数据被缓存到%userprofile%\Local Settings\Temporary Internet Files下一个响应并从缓存中读取.

我认为当这样的代码在ASP.NET应用程序中运行时,数据将被缓存到...\ASPNET\Local Settings\Temporary Internet Files但不是,并且从不使用缓存.

我做错了什么?如何强制HttpWebRequest在ASP.NET环境中使用缓存?

.net asp.net caching httpwebrequest

7
推荐指数
1
解决办法
3129
查看次数

标签 统计

.net ×1

asp.net ×1

caching ×1

httpwebrequest ×1