如何从 IIS7 中删除 eTag 标头?
根据雅虎高性能网站的最佳实践,我想从我的网站中删除 Etag标头(我手动管理所有缓存,不需要 Etag...并且当/如果我需要扩展到农场时,我真的希望它们消失)。 我在 Windows Server 2008 上运行 IIS7。有人知道我该怎么做吗?
Per Yahoo's best practices for high performance web sites, I'd like to remove Etags from my headers (I'm manually managing all my caching and have no need for Etags... and when/if I need to scale to a farm, I'd really like them gone). I'm running IIS7 on Windows Server 2008. Anyone know how I can do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
我们遇到了这个问题,甚至在 IIS 7 中设置空白的自定义 ETag 标头也不适用于所有文件(例如图像文件)。 我们最终创建了一个显式删除 ETag 标头的 HttpModule。
We had this problem, and even setting a blank custom ETag header in IIS 7 was not working for all files (for example image files). We ended up creating an HttpModule that explicitly removes the ETag header.
更新: 感谢用户 @ChrisBarr 添加了 URL 重写模块要求
在 iis 6 中这很简单,您可以在 IIS 7 中为 'ETag' = "" 添加自定义标头
,在阅读此线程并确定它之后如果不使用自定义http模块是不可能的,我发现你可以简单地安装Microsoft的URL重写模块< /a> 并添加出站重写规则,如下所示:
这实际上有效,并且您不需要自定义 http 模块 (dll)。 解锁 system.webServer 配置部分并设置 customHeaders 等不起作用 - 至少在我尝试过的所有情况下都是如此。 一个简单的出站重写规则即可。
UPDATE: added URL Rewrite Module requirement thanks to user @ChrisBarr
In iis 6 it's easy, you can add a custom header for 'ETag' = ""
In IIS 7, after reading this thread and figuring that it was impossible without using a custom http module, I found that you can simply install Microsoft's URL Rewrite module and add an outbound rewrite rule as follows:
This actually works, and you don't need a custom http module (dll). Unlocking the system.webServer configuration section and setting customHeaders, etc., does not work - at least in all the cases I tried. A simple outbound rewrite rule does.
顺便说一句,当您使用iis8时,很简单
IIS 8.0:使用或不使用 ETag
By the way, when you use iis8 it's simple
IIS 8.0: To use or not to use ETag
http ://www.jesscoburn.com/archives/2008/10/02/quickly-configure-or-disable-etags-in-iis7-or-iis6/ 有一个很好的图片指南。
本质上,您创建一个名为 ETag 的自定义响应标头并将其值设为空。
http://www.jesscoburn.com/archives/2008/10/02/quickly-configure-or-disable-etags-in-iis7-or-iis6/ has a nice pictorial guide.
Essentially, you create a custom response header named ETag and make its value empty.
查看这篇博客文章,了解如何完全删除 iis6、iis7 和 iis7.5 中的 Etag http 标头
http://lightspeednow.com/blog/2010/05/21/iis-tutorial -如何从-iis6-iis7-和-iis7-5中完全删除-etags-entity-tags/
Check out this blog post on how to completely remove the Etag http header in iis6,iis7 and iis7.5
http://lightspeednow.com/blog/2010/05/21/iis-tutorial-how-to-completely-remove-etags-entity-tags-from-iis6-iis7-and-iis7-5/
我使用了 http://www 上找到的
removeetag.dll
.caspianit.co.uk/iis7-etag-problem/ 它运行得很好。希望它也适合你
I Used the
removeetag.dll
found on http://www.caspianit.co.uk/iis7-etag-problem/ and it worked perfectly.hope it will work well for you too
在 IIS 7 中,您不必再担心 etag,因为 IIS 配置号始终设置为 0。
如果您有 IIS6 和 IIS,那么仍然存在问题。 同一场中的 IIS7 Web 服务器。 在这种情况下,您必须手动将 IIS6 配置号设置为 0,如 文章。
Etag 实际上非常有用,因为您不需要像堆栈溢出那样更改文件名(即default.css?1234)。 如果更改 default.css 文件,它将更改 etag,因此后续请求将从服务器获取文件而不是缓存。
In IIS 7 you shouldn't have to worry about etags anymore as the IIS configuration number is always set to 0.
There is still a problem if you have IIS6 & IIS7 webservers in the same farm. In this case you would have to manually set the IIS6 config number to 0 as described in this article.
Etags are actually very useful as you don't need to change the filename like stack overflow does (i.e. default.css?1234). If you change the default.css file it will change the etag and therefore subsequent requests will get the file from the server and not the cache.
我认为这会起作用..我知道删除和空白不起作用。
I think this will work .. I know remove and blank doesn't work.
在 IIS7 下,Etag 更改编号(Etag 中以下部分:)始终设置为 0。
因此,同一文件的服务器的 Etag 不再因服务器而异,因此 Yahoo 最佳实践不再真正适用。
由于您实际上无法在 IIS7 上抑制 ETag 标头,因此最好不要摆弄它。 到目前为止,我发现最有用的配置规则是“如果默认设置不会破坏某些内容,则不要管它”。
Under IIS7 the Etag change number (the part of the Etag following : ) is always set to 0.
Hence the Etag from the server no longer varies from server to server for the same file and therefore the Yahoo best practice no longer really applies.
Since you can't actually suppress the ETag header on IIS7 it would probably be best that you don't fiddle with it at all. I've found by far the most useful configuration rule is "If the default doesn't break something, leave it alone".
您可能认为在 web.config 中执行此操作可以禁用 IIS7 中的 ETag。 但嗅探器跟踪确认 ETag 无论如何都已发送。
使用空白也不起作用。 ETag 无论如何都会被发送下来。
按照其他网站的建议将 ETag 设置为空白引号是行不通的。
导致甚至更多 ETag 被发送下来:
总之,我无法尝试或想到任何方法可以杀死 IIS7 上的 ETag,至少在不编写自定义模块等的情况下是如此。
You would think doing this in the web.config would work to disable ETags in IIS7. But sniffer trace confirms that ETag is sent down anyway.
Using blank doesn't work, either. ETag is sent down anyway.
Setting the ETag to blank quotes as other sites have suggested doesn't work.
Causes even more ETag to be sent down:
In conclusion, nothing I can try or think of works to kill ETag on IIS7, at least without writing custom modules, etc.
我编写了一个自定义 http 模块来处理这个问题。 这确实没有听起来那么糟糕。 这是代码:
这是您需要的 web.config 更改:
I wrote a custom http module to handle this. It's really not as bad as it sounds. Here's the code:
Here's the web.config changes you'll want:
我意识到这是一个老问题,但我在寻找解决方案时遇到了它。 我想我找到了一个合理的答案,我为这个问题。
I realize this is an old question, but I came across it while searching for a solution. I think I found a reasonable answer which I posted for this question.