Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 252
Chris Shouts Avatar asked Dec 10 '22 19:12

Chris Shouts


1 Answers

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!

like image 99
Chris Shouts Avatar answered Dec 27 '22 05:12

Chris Shouts