根据雅虎针对高性能网站的最佳做法,我想从我的标题中删除Etags(我手动管理所有缓存,不需要Etags ......以及何时/如果我需要扩展到农场,我真的很喜欢他们走了).我在Windows Server 2008上运行IIS7.任何人都知道我该怎么做?
Ant*_*nes 39
在IIS7下,Etag更改编号(以下Etag的部分)始终设置为0.
因此,服务器上的Etag不再因服务器而异,因此雅虎的最佳实践不再适用.
由于你无法在IIS7上实际上压制ETag标头,所以最好不要使用它.到目前为止,我发现最有用的配置规则是"如果默认不破坏某些东西,请不要理会".
Jef*_*ood 33
您可能会认为在web.config中执行此操作可以在IIS7中禁用ETag.但是嗅探器跟踪证实了ETag无论如何都被发送了.
<httpProtocol>
    <customHeaders>
        <remove name="ETag" />
    </customHeaders>
</httpProtocol>
使用空白也不起作用.无论如何ETag都被送了下来.
<httpProtocol>
    <customHeaders>
        <add name="ETag" value="" />
    </customHeaders>
</httpProtocol>
将ETag设置为其他站点建议的空白引号不起作用.
<httpProtocol>
    <customHeaders>
        <add name="ETag" value="""" />
    </customHeaders>
</httpProtocol>
导致更多 ETag被发送:
ETag: "8ee1ce1acf18ca1:0",""
总而言之,我无法尝试或想到的任何东西都可以杀死IIS7上的ETag,至少不需要编写自定义模块等.
Dan*_*Dan 23
我写了一个自定义的http模块来处理这个问题.它真的没那么糟糕.这是代码:
using System;
using System.Web;
namespace StrongNamespace.HttpModules
{
    public class CustomHeaderModule : IHttpModule
    {
        public void Init(HttpApplication application)
        {
            application.PostReleaseRequestState += new EventHandler(application_PostReleaseRequestState);
        }
        public void Dispose()
        {
        }
        void application_PostReleaseRequestState(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Headers.Remove("Server");
            HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
            HttpContext.Current.Response.Headers.Remove("ETag");
        }
    }
}
这是您想要的web.config更改:
<configuration>
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <remove name="X-Powered-By"/>
            </customHeaders>
        </httpProtocol>
        <modules>
            <add name="CustomHeaderModule" type="StrongNamespace.HttpModules.CustomHeaderModule"/>
        </modules>
    </system.webServer>
</configuration>
更新:感谢用户@ChrisBarr添加了URL重写模块的要求
在iis 6中很容易,您可以为'ETag'=""添加自定义标题
在IIS 7中,在阅读此线程并确定不使用自定义http模块后无法实现之后,我发现您只需安装Microsoft的URL Rewrite模块并添加出站重写规则,如下所示:
<outboundRules>
  <rule name="Remove ETag">
    <match serverVariable="RESPONSE_ETag" pattern=".+" />
    <action type="Rewrite" value="" />
  </rule>
</outboundRules>
这实际上有效,您不需要自定义http模块(dll).解锁system.webServer配置部分和设置customHeaders等不起作用 - 至少在我尝试过的所有情况下都是如此.一个简单的出站重写规则.
http://www.jesscoburn.com/archives/2008/10/02/quickly-configure-or-disable-etags-in-iis7-or-iis6/有一个很好的图片指南。
本质上,您创建一个名为 ETag 的自定义响应标头并将其值设为空。
| 归档时间: | 
 | 
| 查看次数: | 39422 次 | 
| 最近记录: |