views:

2057

answers:

1

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 http://stackoverflow.com/questions/713581/asp-net-app-set-ie7-compatibility-mode but it does not appear to be working as expected using IE8 and IIS6. Any hints?

+4  A: 

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!

Chris Shouts