2012-05-18 48 views
17

我无法获取图像文件缓存。我尝试了在本网站和其他网站上找到的所有内容,但仍然无法让它们缓存。我曾尝试IIS 7.5和图像未被缓存

<staticContent> 
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" /> 
    </staticContent> 
    <httpProtocol allowKeepAlive="true" /> 


    <caching enabled="true" enableKernelCache="true"> 
    <profiles> 
    <add extension=".png" policy="CacheUntilChange" /> 
    <add extension=".jpg" policy="CacheForTimePeriod" duration="12:00:00" /> 
    </profiles> 
    </caching> 

这里

的Web配置设置对于图像的1响应头

Key Value 
    Response HTTP/1.1 200 OK 
    Cache-Control no-cache 
    Content-Type image/png 
    Last-Modified Thu, 16 Dec 2004 18:33:28 GMT 
    Accept-Ranges bytes 
    ETag "a1ca4bc9de3c41:0" 
    Server Microsoft-IIS/7.5 
    X-Powered-By ASP.NET 
    Date Fri, 18 May 2012 13:21:21 GMT 
    Content-Length 775 
+1

IIS默认缓存静态内容。当您检查标题时,请确保您的开发工具没有设置为禁用缓存的选项。 – ajbeaven

回答

29

下应该引起浏览器缓存您的图片:

<staticContent> 
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" /> 
</staticContent> 
<httpProtocol> 
    <customHeaders> 
     <add name="Cache-Control" value="public" /> 
    </customHeaders> 
</httpProtocol> 

<caching>...</caching>块用于服务器端的缓存,而不是客户端的cachin G。

+1

这是否启用每个静态文件(.js,.css,.jpg等)上的客户端缓存标头?我怎样才能控制扩展?谢谢 – Andres

+3

它启用文件夹(和子文件夹)中的所有静态内容(在IIS中启用)的缓存标头,并使用“web.config”文件启用此功能。因此,如果你的图像在'/ images'中,你应该使用上面的'web.config'并将它放在'/ images'文件夹中,这样只有图像受到这个影响。您无法为每个文件扩展名启用/禁用它。 –

+0

这会导致500.19错误,我该怎么办? – Digerkam