ASP.NET Ignores IE7 Compatibility Mode Tag in Web.config

18,946

Turns out the problem was that I'm using IIS6. IIS6 looks at the <system.web> section of Web.config instead of the <system.webServer> section (which is used by IIS7, unless it's running in compatibility mode). To render this meta tag on every page of your site when running IIS6, I believe the best option is to add it to your MasterPage. I ended up adding the following code block to the OnPreRender event of my MasterPage:

Page.Header.Controls.AddAt(0, new HtmlMeta { HttpEquiv = "X-UA-Compatible", Content = "IE=EmulateIE7" });

The reason I used AddAt instead of just plain Add is because the X-UA-Compatible meta tag apparently has to be the first thing in the page header in order for it to be respected.

Hope this helps someone in the same boat!

Share:
18,946
Chris Shouts
Author by

Chris Shouts

Dedicated software engineer with over a decade of experience building web applications. Inspired by the twelve-factor app process, resilient web design, and the agile manifesto.

Updated on August 03, 2022

Comments

  • Chris Shouts
    Chris Shouts over 1 year

    I have the following section in my Web.config file

    <system.webServer>
        <!-- For now..... lets be safe and put IE8 in IE7 compatibility mode-->
        <httpProtocol>
          <customHeaders>
            <clear />
            <add name="X-UA-Compatible" value="IE=EmulateIE7" />
          </customHeaders>
        </httpProtocol>
    </system.webServer>
    

    but the

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

    is not present in the header of the pages when they are rendered on my site. I followed the advice in this post ASP.NET App - Set IE7-Compatibility Mode? but it does not appear to be working as expected using IE8 and IIS6. Any hints?