Disable Internet Explorer compatibility view via web.config

New Internet Explorers have a necessary (?) but annoying feature called “Compatibility view”. I do not need that in my sites since I try to keep my HTML in good shape. Therefore on all projects I want to disable the feature since usually it breaks the layout. Disabling compatibility view can be done by adding a meta tag to HTML head:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

…or, as it turns out, by adding a custom HTTP header with the same content. This HTTP-header-way is much better for me as I can include it in my default web.config changes I use on almost every web project.

<system.webserver>
  <httpProtocol>
    <customHeaders>
      <!-- No need to expose the platform -->
      <remove
        name="X-Powered-By" />
      <!-- Do not show IE compatibility view -->
      <remove
        name="X-UA-Compatible"/>
      <add
        name="X-UA-Compatible"
        value="IE=edge"/>
    </customHeaders>
  </httpProtocol>

Update 4.2.2014

Check my newer post for better solution that covers more IE versions.