如何强制HttpWebRequest的在ASP.NET环境中使用缓存? [英] How to force HttpWebRequest to use cache in ASP.NET environment?

查看:288
本文介绍了如何强制HttpWebRequest的在ASP.NET环境中使用缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET应用程序我使用HttpWebRequest的包括获取我想要缓存哪些外部资源。请看下面的code:

In my ASP.NET app I use HttpWebRequest for fetching external resources which I'd like to be cached. Consider the following code:

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);

HttpWebRequest的使用IE缓存,所以当我运行它作为普通用户(在微小的CMD测试程序),数据缓存到%USERPROFILE%\\本地设置\\ Temporary Internet Files文件和明年响应从缓存中读取。

HttpWebRequest uses IE cache, so when I run it as normal user (in tiny cmd test app), data is cached to %userprofile%\Local Settings\Temporary Internet Files and next responses are read from cache.

我想,当这样的code为ASP.NET应用程序中运行,数据将被缓存到 ... \\ ASPNET \\本地设置\\ Temporary Internet Files文件但它不是与从不使用高速缓存。

I thought that when such code is run inside ASP.NET app, data will be cached to ...\ASPNET\Local Settings\Temporary Internet Files but it is not and cache is never used.

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

What I am doing wrong? How to force HttpWebRequest to use cache in ASP.NET environment?

推荐答案

我知道这是一个古老的线程,但另一个要考虑的就这个问题是用户的IE浏览器的安全设置帐号的ASP.NET应用程序作为。 HTTP缓存(CachePolicy.Level =默认,HTTP缓存资源)没有工作对我们的应用程序,直到我们增加了远程主机到受信任站点列表中。

I know this is an old thread, but another thing to consider regarding this issue is the IE security settings for the user account the ASP.NET application is running as. HTTP caching (CachePolicy.Level = Default, HTTP cacheable resources) was not working for our application until we added the remote host to the Trusted Sites list.

这文章是对我们的缓存故障排除有用:<一href=\"http://blogs.msdn.com/b/ieinternals/archive/2011/03/19/wininet-temporary-internet-files-cache-and-explorer-folder-view.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/ieinternals/archive/2011/03/19/wininet-temporary-internet-files-cache-and-explorer-folder-view.aspx

This article was useful for our cache troubleshooting: http://blogs.msdn.com/b/ieinternals/archive/2011/03/19/wininet-temporary-internet-files-cache-and-explorer-folder-view.aspx

这篇关于如何强制HttpWebRequest的在ASP.NET环境中使用缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆