ASP.NET忽略Web.config中的IE7兼容性模式标记 [英] ASP.NET Ignores IE7 Compatibility Mode Tag in Web.config

查看:390
本文介绍了ASP.NET忽略Web.config中的IE7兼容性模式标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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>

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

不会出现在页面的标题中。我遵循这篇文章中的建议 ASP.NET应用程序 - 设置IE7兼容模式? ,但它似乎没有按预期使用IE8和IIS6工作。任何提示?

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?

推荐答案

问题是我使用 IIS6 。 IIS6查看Web.config的< system.web> 部分,而不是< system.webServer> 部分(由IIS7使用,除非它以兼容模式运行)。要在运行IIS6时在网站的每个页面上呈现此元标记,我相信最好的选择是将其添加到您的MasterPage。我最后添加以下代码块到我的MasterPage的OnPreRender事件:

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" });

我使用AddAt而不是简单的Add的原因是因为X-UA-Compatible元标签显然

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!

这篇关于ASP.NET忽略Web.config中的IE7兼容性模式标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆