迁移的 Web 表单应用程序 .NET 2.0 -> 3.5、新基础设施——IE 6中图像不缓存
我一直在迁移 .NET 2.0 Web 表单应用程序以使用 .NET 3.5 和新的基础设施。 UpdatePanel 内有一个 GridView,其中有一个“操作”列,其中包含用于对该行执行操作的图标。我在 IE 6 中遇到的一个问题是图像没有缓存。这在“操作”列上尤其明显,因为有 9 个图标 x 100 行 = 900 个图标要加载。 Internet Explorer 从 900 个图像开始倒计时,直到它们全部加载完毕。
这个问题似乎并不局限于 UpdatePanel 内的 GridView 内的图像,因为我可以看到每次页面刷新时都会重新加载标题图像。
我已经完成了我的研究:
- 有人有解决 Internet Explorer 上的“剩余 n 项”问题的想法吗? - 这是一个不同的问题。
- 亲爱的 IE6:请缓存我的图像。 -我确实认为这可以解决所有问题,但事实并非如此。我尝试将图像设置为 div 内的背景图像,但没有成功。我还尝试将所有图标放入用户控件中,并在加载 GridView 之前将其包括在内。
- 我有一个旧的基础设施(不存在这个问题)来比较 IIS 配置,它们是完全相同的。
- 使用 Fiddler,我可以令人沮丧地看到每个被请求的图像。缓存标头是
Cache-Control: private
。刚刚注意到此缓存标头中的Date: Tue, 29 Mar 2011 07:35:53 GMT
(一小时前)。这有什么关系吗? - 此缓存问题似乎是间歇性的。我将第一次加载页面,并且不会缓存任何图像,因此将独立加载约 1000 个图像。我可能会刷新页面并且图像将被缓存。如果我删除所有临时文件/脱机内容,则图像将再次独立加载。
- 起初,我认为这只发生在将应用程序部署到新基础设施时(跨林发出请求),但当所有图像都是本地时,它也会发生在我的本地计算机上。
- 这只是 IE 6 中的问题!!!
如果我可以提供其他信息,请告诉我。
更新 1
已尝试但未成功的解决方法:
- @Afshin Gh 提出的处理程序解决方案。 更新2答案中的代码确实有效。之前必须尝试过不同的版本。
- @Blue Steel 提出的隐藏图像解决方案。
更新2
其他一些解决方案可能在这里有效,但我使用了@Afshin Gh提供的代码。
I have been migrating a .NET 2.0 web forms application to use .NET 3.5 and a new infrastructure. There is a GridView inside an UpdatePanel, with an Actions column which contains icons to perform an action for that row. A problem that I am having in IE 6 is that images are not caching. This is particularly noticeable on the Actions column because there are 9 icons x 100 rows = 900 icons to load. Internet Explorer counts down these images from 900 until they are all loaded.
This problem does not appear to be limited to the images inside the GridView which is inside an UpdatePanel because I can see header images being reloaded each time there is a page refresh.
I have done my research:
- Anyone have ideas for solving the "n items remaining" problem on Internet Explorer? - this is a different problem.
- Dear IE6: Please Cache my Images. - I did think that this would solve all of the problems, but no. I have tried setting the image as a background image inside a div but no success. I also tried putting all icons inside a User Control and including this before the GridView is loaded.
- I have an old infrastructure (where this problem did not exist) to compare IIS configurations and they are exactly the same.
- Using Fiddler I can frustratingly see each image being requested. The Cache Header is
Cache-Control: private
. Just noticedDate: Tue, 29 Mar 2011 07:35:53 GMT
(which is an hour ago) in this Cache Header. Does that have anything to do with it? - This caching problem appears to be intermittent. I will load the page up for the first time and no images will be cached so ~1000 images will be independently loaded. I may refresh the page and images will be cached. If I delete all temporary files/offline content then the images will be loaded independently again.
- At first I thought this only occurred when deploying the application to the new infrastructure (requests being made cross-forest) but it does happen on my local machine too when all images are local.
- This is only a problem in IE 6!!!
Please let me know if I can provide other information.
UPDATE 1
Workarounds which have already been attempted with no success:
- The handler solution proposed by @Afshin Gh. UPDATE 2 The code in the answer actually works. A different version must have been attempted previously.
- The hidden images solution proposed by @Blue Steel.
UPDATE 2
Some of the other solutions may have worked here but I have gone with the code provided by @Afshin Gh.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用此处理程序:
在 web.config 中注册它:
像这样使用它:
Use this handler:
Register it in your web.config:
Use it like this:
fiddler 是否也显示其他浏览器的缓存控制:私有?如果是这样,它们也不会被缓存。您是否使用自定义控件来提供网格中的图像?如果是这样,您可能没有正确处理缓存标头(包括 304 响应等)。
Does fiddler show cache control: private for other browsers as well? If so they won't be cached either. Are you using a custom control to serve up the images in the grid? If so you probably aren't handling the cache headers correctly (including 304 responses etc).
我建议在标头上设置此缓存参数。
您可以在这里阅读更多信息 http://www.rdlt.com /cache-control-post-check-pre-check.html 或谷歌它。
检查一下并告诉我这是否可以解决您的问题。
I suggest to set this cache parameters on header.
You can read more about here http://www.rdlt.com/cache-control-post-check-pre-check.html or google it.
Check it out and tell me if this solve your issue.
您是否尝试过将 9 个图像添加到页面顶部(更新面板之外)但设置为隐藏?
Have you tried adding the 9 images to the top of your page (outside the update panel) but set to hidden?