IIS 7队新鲜图片 [英] IIS 7 Force Fresh Images
问题描述
如何强制IIS 7为不可以缓存图片为特定的页面?
How do I force IIS 7 to not cache images for a particular page?
推荐答案
在IIS7,你可以在你的web.config,或以编程方式做到这一点无论声明。
In IIS7, you can do this either declaratively in your web.config, or programmatically.
<location path="YourPath">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
的编程解决方案要求的登记在集成模式下所有的请求,在那里你看那些你关心的URL运行一个简单的HTTP模块。然后调用:
The programmatic solution requires a simple HttpModule that's registered to run for all requests in Integrated mode, where you look for the URLs that you're concerned about. Then call:
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
FWIW,你可能要考虑禁用唯一客户端缓存,同时支持服务器端缓存,使用 HttpCacheability.ServerAndNoCache
。另外,如果你的图像名称添加查询字符串,您将通过HTTP.SYS prevent服务器端缓存。
FWIW, you may want to consider disabling client-side caching only, while enabling server-side caching, by using HttpCacheability.ServerAndNoCache
. Also, if you add a query string on the image names, you will prevent server-side caching by http.sys.
在情况下,它可以帮助,我盖像这些在我的书中详细技术:超快速ASP.NET
In case it helps, I cover techniques like these in detail in my book: Ultra-Fast ASP.NET.
这篇关于IIS 7队新鲜图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!