如何从IIS7中删除eTag头文件?

时间:2022-09-25 12:36:01

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?

根据Yahoo为高性能web站点提供的最佳实践,我想从我的头文件中删除Etags(我手工管理所有的缓存,不需要Etags…)如果我需要搬到农场,我真的希望他们离开)。我在Windows Server 2008上运行IIS7。有人知道我怎么做吗?

12 个解决方案

#1


39  

Under IIS7 the Etag change number (the part of the Etag following : ) is always set to 0.

在IIS7下,Etag更改号(Etag的以下部分:)总是设置为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.

因此,服务器上的Etag不再因服务器而异,因此Yahoo的最佳实践不再适用。

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".

由于您不能实际地抑制IIS7上的ETag头,所以最好完全不要摆弄它。我发现,到目前为止,最有用的配置规则是“如果默认值不破坏什么,那就别管它”。

#2


32  

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.

你可能会认为在网上这么做。配置可以在IIS7中禁用ETags。但嗅探器追踪证实,ETag无论如何都会被发送下去。

<httpProtocol>
    <customHeaders>
        <remove name="ETag" />
    </customHeaders>
</httpProtocol>

Using blank doesn't work, either. ETag is sent down anyway.

使用空格也不行。不管怎样,ETag是被送下去的。

<httpProtocol>
    <customHeaders>
        <add name="ETag" value="" />
    </customHeaders>
</httpProtocol>

Setting the ETag to blank quotes as other sites have suggested doesn't work.

像其他网站建议的那样将ETag设置为空引号是行不通的。

<httpProtocol>
    <customHeaders>
        <add name="ETag" value="&quot;&quot;" />
    </customHeaders>
</httpProtocol>

Causes even more ETag to be sent down:

导致更多的ETag被发送:

ETag: "8ee1ce1acf18ca1:0",""

In conclusion, nothing I can try or think of works to kill ETag on IIS7, at least without writing custom modules, etc.

综上所述,我无法尝试或想象在IIS7上杀死ETag,至少不需要编写自定义模块等等。

#3


23  

I wrote a custom http module to handle this. It's really not as bad as it sounds. Here's the code:

我编写了一个自定义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");
        }
    }
}

Here's the web.config changes you'll want:

这是网络。配置更改你需要:

<configuration>
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <remove name="X-Powered-By"/>
            </customHeaders>
        </httpProtocol>
        <modules>
            <add name="CustomHeaderModule" type="StrongNamespace.HttpModules.CustomHeaderModule"/>
        </modules>
    </system.webServer>
</configuration>

#4


13  

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.

我知道这是一个老问题,但我是在寻找解决方案时遇到它的。我想我找到了一个合理的答案。

#5


7  

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.

我们遇到了这个问题,甚至在IIS 7中设置一个空白的自定义ETag头也不能用于所有文件(例如图像文件)。我们最终创建了一个HttpModule,它显式地删除ETag头。

#6


6  

UPDATE: added URL Rewrite Module requirement thanks to user @ChrisBarr

更新:由于用户@ChrisBarr,增加了URL重写模块的需求

In iis 6 it's easy, you can add a custom header for 'ETag' = ""

在iis 6中,很容易,您可以为“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:

在IIS 7中,在阅读了这个线程并发现不使用自定义http模块是不可能的之后,我发现您只需安装Microsoft的URL重写模块并添加出站重写规则如下:

<outboundRules>
  <rule name="Remove ETag">
    <match serverVariable="RESPONSE_ETag" pattern=".+" />
    <action type="Rewrite" value="" />
  </rule>
</outboundRules>

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.

这实际上是可行的,而且您不需要自定义http模块(dll)。打开系统。webServer配置部分和设置customheader等不能工作——至少在我尝试过的所有情况下是这样。一个简单的出站重写规则就可以做到这一点。

#7


4  

By the way, when you use iis8 it's simple

顺便说一下,使用iis8很简单

<element name="clientCache">
   <attribute name="cacheControlMode" type="enum" defaultValue="NoControl">
          <enum name="NoControl" value="0" />
          <enum name="DisableCache" value="1" />
          <enum name="UseMaxAge" value="2" />
          <enum name="UseExpires" value="3" />
  </attribute>
  <attribute name="cacheControlMaxAge" type="timeSpan" defaultValue="1.00:00:00" />
  <attribute name="httpExpires" type="string" />
  <attribute name="cacheControlCustom" type="string" />
  <attribute name="setEtag" type="bool" defaultValue="true" />
</element>

IIS 8.0: To use or not to use ETag

iis8.0:使用或不使用ETag

#8


2  

http://www.jesscoburn.com/archives/2008/10/02/quickly-configure-or-disable-etags-in-iis7-or-iis6/ has a nice pictorial guide.

http://www.jesscoburn.com/archives/2008/10/02/quick -configure- disable-etag -in iis7-or-iis6/有一个很好的图片指南。

Essentially, you create a custom response header named ETag and make its value empty.

本质上,您创建了一个名为ETag的自定义响应头,并使其值为空。

#9


2  

Check out this blog post on how to completely remove the Etag http header in iis6,iis7 and iis7.5

查看这篇关于如何完全删除iis6、iis7和iis7.5中的Etag http头的博文

http://lightspeednow.com/blog/2010/05/21/iis-tutorial-how-to-completely-remove-etags-entity-tags-from-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/

#10


2  

I Used the removeetag.dll found on http://www.caspianit.co.uk/iis7-etag-problem/ and it worked perfectly.

我使用了removeetag。dll在http://www.caspianit.co.uk/iis7-etag-problem/上找到,并且运行良好。

hope it will work well for you too

希望它对你也有好处

#11


1  

In IIS 7 you shouldn't have to worry about etags anymore as the IIS configuration number is always set to 0.

在IIS 7中,您不必再担心etags,因为IIS配置号总是设置为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.

如果在同一个农场中有IIS6和IIS7 web服务器,仍然存在问题。在这种情况下,您必须手动将IIS6配置号设置为0,如本文所述。

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.

Etags实际上非常有用,因为您不需要像stack overflow那样更改文件名(也就是default.css?1234)。如果你改变了默认值。它将更改etag文件,因此后续请求将从服务器而不是缓存获得文件。

#12


1  

I think this will work .. I know remove and blank doesn't work.

我想这行得通。我知道删除和空白不起作用。

    <configuration>
     <system.webServer>
       <httpProtocol>
          <customHeaders>
            <add name="ETag" value=" " /> 
          </customHeaders>
        </httpProtocol>
       </configuration>
     </system.webServer>

#1


39  

Under IIS7 the Etag change number (the part of the Etag following : ) is always set to 0.

在IIS7下,Etag更改号(Etag的以下部分:)总是设置为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.

因此,服务器上的Etag不再因服务器而异,因此Yahoo的最佳实践不再适用。

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".

由于您不能实际地抑制IIS7上的ETag头,所以最好完全不要摆弄它。我发现,到目前为止,最有用的配置规则是“如果默认值不破坏什么,那就别管它”。

#2


32  

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.

你可能会认为在网上这么做。配置可以在IIS7中禁用ETags。但嗅探器追踪证实,ETag无论如何都会被发送下去。

<httpProtocol>
    <customHeaders>
        <remove name="ETag" />
    </customHeaders>
</httpProtocol>

Using blank doesn't work, either. ETag is sent down anyway.

使用空格也不行。不管怎样,ETag是被送下去的。

<httpProtocol>
    <customHeaders>
        <add name="ETag" value="" />
    </customHeaders>
</httpProtocol>

Setting the ETag to blank quotes as other sites have suggested doesn't work.

像其他网站建议的那样将ETag设置为空引号是行不通的。

<httpProtocol>
    <customHeaders>
        <add name="ETag" value="&quot;&quot;" />
    </customHeaders>
</httpProtocol>

Causes even more ETag to be sent down:

导致更多的ETag被发送:

ETag: "8ee1ce1acf18ca1:0",""

In conclusion, nothing I can try or think of works to kill ETag on IIS7, at least without writing custom modules, etc.

综上所述,我无法尝试或想象在IIS7上杀死ETag,至少不需要编写自定义模块等等。

#3


23  

I wrote a custom http module to handle this. It's really not as bad as it sounds. Here's the code:

我编写了一个自定义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");
        }
    }
}

Here's the web.config changes you'll want:

这是网络。配置更改你需要:

<configuration>
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <remove name="X-Powered-By"/>
            </customHeaders>
        </httpProtocol>
        <modules>
            <add name="CustomHeaderModule" type="StrongNamespace.HttpModules.CustomHeaderModule"/>
        </modules>
    </system.webServer>
</configuration>

#4


13  

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.

我知道这是一个老问题,但我是在寻找解决方案时遇到它的。我想我找到了一个合理的答案。

#5


7  

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.

我们遇到了这个问题,甚至在IIS 7中设置一个空白的自定义ETag头也不能用于所有文件(例如图像文件)。我们最终创建了一个HttpModule,它显式地删除ETag头。

#6


6  

UPDATE: added URL Rewrite Module requirement thanks to user @ChrisBarr

更新:由于用户@ChrisBarr,增加了URL重写模块的需求

In iis 6 it's easy, you can add a custom header for 'ETag' = ""

在iis 6中,很容易,您可以为“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:

在IIS 7中,在阅读了这个线程并发现不使用自定义http模块是不可能的之后,我发现您只需安装Microsoft的URL重写模块并添加出站重写规则如下:

<outboundRules>
  <rule name="Remove ETag">
    <match serverVariable="RESPONSE_ETag" pattern=".+" />
    <action type="Rewrite" value="" />
  </rule>
</outboundRules>

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.

这实际上是可行的,而且您不需要自定义http模块(dll)。打开系统。webServer配置部分和设置customheader等不能工作——至少在我尝试过的所有情况下是这样。一个简单的出站重写规则就可以做到这一点。

#7


4  

By the way, when you use iis8 it's simple

顺便说一下,使用iis8很简单

<element name="clientCache">
   <attribute name="cacheControlMode" type="enum" defaultValue="NoControl">
          <enum name="NoControl" value="0" />
          <enum name="DisableCache" value="1" />
          <enum name="UseMaxAge" value="2" />
          <enum name="UseExpires" value="3" />
  </attribute>
  <attribute name="cacheControlMaxAge" type="timeSpan" defaultValue="1.00:00:00" />
  <attribute name="httpExpires" type="string" />
  <attribute name="cacheControlCustom" type="string" />
  <attribute name="setEtag" type="bool" defaultValue="true" />
</element>

IIS 8.0: To use or not to use ETag

iis8.0:使用或不使用ETag

#8


2  

http://www.jesscoburn.com/archives/2008/10/02/quickly-configure-or-disable-etags-in-iis7-or-iis6/ has a nice pictorial guide.

http://www.jesscoburn.com/archives/2008/10/02/quick -configure- disable-etag -in iis7-or-iis6/有一个很好的图片指南。

Essentially, you create a custom response header named ETag and make its value empty.

本质上,您创建了一个名为ETag的自定义响应头,并使其值为空。

#9


2  

Check out this blog post on how to completely remove the Etag http header in iis6,iis7 and iis7.5

查看这篇关于如何完全删除iis6、iis7和iis7.5中的Etag http头的博文

http://lightspeednow.com/blog/2010/05/21/iis-tutorial-how-to-completely-remove-etags-entity-tags-from-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/

#10


2  

I Used the removeetag.dll found on http://www.caspianit.co.uk/iis7-etag-problem/ and it worked perfectly.

我使用了removeetag。dll在http://www.caspianit.co.uk/iis7-etag-problem/上找到,并且运行良好。

hope it will work well for you too

希望它对你也有好处

#11


1  

In IIS 7 you shouldn't have to worry about etags anymore as the IIS configuration number is always set to 0.

在IIS 7中,您不必再担心etags,因为IIS配置号总是设置为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.

如果在同一个农场中有IIS6和IIS7 web服务器,仍然存在问题。在这种情况下,您必须手动将IIS6配置号设置为0,如本文所述。

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.

Etags实际上非常有用,因为您不需要像stack overflow那样更改文件名(也就是default.css?1234)。如果你改变了默认值。它将更改etag文件,因此后续请求将从服务器而不是缓存获得文件。

#12


1  

I think this will work .. I know remove and blank doesn't work.

我想这行得通。我知道删除和空白不起作用。

    <configuration>
     <system.webServer>
       <httpProtocol>
          <customHeaders>
            <add name="ETag" value=" " /> 
          </customHeaders>
        </httpProtocol>
       </configuration>
     </system.webServer>