IIS 8.0: To use or not to use ETag, that is the question.

In this blog, I will not discuss what ETag is or whether I agree with some of the articles that have written around whether the use of ETag is a good or a bad idea.

But if you found this blog, it's probably because you have read some of these articles, as well as a number of blogs and forums on how you can disable IIS from sending the ETag response.   (I will say, however, that many of them are incorrect.)

Well, with IIS 8.0 beta in Windows Server 8 beta, it is actually rather simple.   I don't know if anyone has been looking at the changes in the IIS_schema.xml, but if you have, you may have noticed the following:

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

That's right.   There is an attribute for that. :)

By default, the value is set to "true", so when you send a GET request, you will observe:

   HTTP/1.1 200 OK\r\n
   Content-Type: text/html\r\n
   Last-Modified: Tue, 28 Feb 2012 19:04:57 GMT\r\n
   Accept-Ranges: bytes\r\n
   ETag: "25c7dadc4bf6cc1:0"\r\n
   Server: Microsoft-IIS/8.0\r\n
   Date: Sat, 31 Mar 2012 02:14:16 GMT\r\n
   Content-Length: 1398\r\n  

However, if you set this value to "false" in applicationHost.config file, like so:

<staticContent enableDocFooter="false" lockAttributes="isDocFooterFileName">
    <mimeMap fileExtension=".323" mimeType="text/h323" />
    <mimeMap fileExtension=".3g2" mimeType="video/3gpp2" />
    <mimeMap fileExtension=".3gp2" mimeType="video/3gpp2" />
    .
    .
    .
  <clientCache setEtag="false" />
</staticContent>   

Then, now the same GET request does not have the ETag in the response header:

   HTTP/1.1 200 OK\r\n
   Content-Type: text/html\r\n
   Last-Modified: Tue, 28 Feb 2012 19:04:57 GMT\r\n
   Accept-Ranges: bytes\r\n
   Server: Microsoft-IIS/8.0\r\n
   Date: Sat, 31 Mar 2012 02:13:54 GMT\r\n
   Content-Length: 1398\r\n

Hope everyone is discovering the new features in IIS 8.0 beta.   Please let us know how you like them and how we can improve.  (By the way, did you also notice "Server: Microsoft-IIS/8.0"?   And have you noticed how all the traffic from www.iis.net have them?   Yes, we are running 100% on IIS 8.0 beta.)

2 Comments

Comments have been disabled for this content.