以下配置应该会导致浏览器将您的图像缓存一整年:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="public" />
</customHeaders>
</httpProtocol>
您只需要确保您的图片是作为静态文件类型提供的。没有办法强制浏览器不向服务器发送请求,即;用户执行硬刷新。
您可以将上述配置包装在位置节点中,以便仅影响位于特定路径中的图像:
<location path="Content">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="public" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
上述配置将为http://www.example.com/Content/Images/* 托管的所有图像添加一个 HTTP 缓存标头指令
您应该创建一个可配置的应用设置,将其作为查询字符串参数传递到此类图像 URI。这将允许您清除所有客户端以从您的服务器发送图像请求:(我们希望对此进行控制,因为缓存的图像可能会出现问题)
<img src="/Content/Images/MyImage.jpg?version=<%# Global.ImageVersion %>" />
更多关于缓存头(Cache-Control)的信息在这里http://www.mobify.com/blog/beginners-guide-to-http-cache-headers/
希望对你有帮助!