问题
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?
回答1:
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!
来源:https://stackoverflow.com/questions/1209183/asp-net-ignores-ie7-compatibility-mode-tag-in-web-config