【问题标题】:IE doesn't seem to cache my imagesIE 似乎没有缓存我的图片
【发布时间】:2011-11-02 17:31:02
【问题描述】:

我真的希望有人有一些想法。我已将我的网络配置设置为将图像缓存 30 天。

web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>

然而,当我使用 IE 请求页面并检查网络流量时,我看到的是:

Request Header:

Key Value
Request GET http://www.xx.com/Content/Icons/login.png HTTP/1.1
Accept  image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5
Referer http://www.selftestware.com/
Accept-Language en-US
User-Agent  Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Accept-Encoding gzip, deflate
Host    www.xx.com
If-Modified-Since   Wed, 24 Aug 2011 15:48:10 GMT
If-None-Match   W/"0195d397562cc1:0"
Proxy-Connection    Keep-Alive
Pragma  no-cache
Cookie  __utma=xx

Response:

Key Value
Response    HTTP/1.1 200 OK
Cache-Control   public,max-age=2592000
Content-Type    image/png
Last-Modified   Wed, 24 Aug 2011 15:48:10 GMT
Accept-Ranges   bytes
ETag    W/"0195d397562cc1:0"
Server  Microsoft-IIS/7.5
X-Powered-By    ASP.NET
Date    Wed, 24 Aug 2011 10:39:14 GMT
Content-Length  727

它应该不发送 304(未修改)。我就是不明白这里出了什么问题。

【问题讨论】:

  • 为什么会在请求头中看到“Pragma no-cache”??
  • 这不是我设定的。我的应用程序是在 WIndows Azure 上运行的开箱即用的 MVC3 实现。
  • 我认为你必须找到一种方法来删除它..!
  • 在这种情况下,“pragma: no-cache”是一条红鲱鱼 - 我在请求标头中看到了这一点,但仍按预期得到 304 响应。

标签: asp.net html css asp.net-mvc iis-7


【解决方案1】:

你的请求头被发送了一个“Pragma: no-cache”,这意味着告诉服务器不要缓存这个请求。这就是为什么您的服务器响应 HTTP 200 而不是 HTTP 304。

这个“Pragma: no-cache”是由浏览器发送的。如果您按 Ctrl+F5 热键或将浏览器配置为不缓存任何内容,则会导致此结果。您可以尝试创建一个包含指向此缓存页面的链接的空白页面,然后单击其上的链接。您会看到此页面已被缓存。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 2020-02-24
    • 1970-01-01
    • 2021-03-25
    • 2012-05-30
    相关资源
    最近更新 更多