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

别来无恙 提交于 2019-12-03 19:39:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!