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

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

问题描述

我有以下的部分,我的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"/>

不在的时候都在我的网站提供的页面的标题present。我跟着这个职位的建议<一href=\"http://stackoverflow.com/questions/713581/asp-net-app-set-ie7-compatibility-mode\">http://stackoverflow.com/questions/713581/asp-net-app-set-ie7-compatibility-mode但它不会出现要工作作为使用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 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?

推荐答案

原来,问题是,我使用的 IIS6 。 IIS6着眼于&LT;的System.Web&GT; Web.config文件,而不是部分的&LT; system.webServer&GT; 部分(它是由IIS7使用的,除非它在兼容模式运行)。要在运行时IIS6渲染网站的每个网页上的这个元标记,我相信最好的选择是将其添加到您的母版。我最终加入以下code座我母版的在preRender事件:

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,而不是只是简单的添加的原因是因为X-UA兼容meta标签显然已经是在页面头部的第一件事,以便它得到尊重。

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忽略IE7兼容模式标签在Web.config中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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