如何有力地从服务器端设置IE的兼容模式了吗? [英] How to forcefully set IE's Compatibility Mode off from the server-side?

查看:128
本文介绍了如何有力地从服务器端设置IE的兼容模式了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在域控制的环境我发现,在兼容模式触发某些客户端(操作系统/ Win7的,IE8 / IE9),即使我们提供的X UA标签,一!DOCTYPE定义和IE =边缘的响应头。这些客户有复选框选中了在兼容性视图中显示Intranet站点。这是precisely我想要重写。

In a domain-controlled environment I'm finding that the compatibility mode is triggered on certain clients (winXP/Win7, IE8/IE9) even when we are providing a X-UA tags, a !DOCTYPE definition and "IE=Edge" response headers. These clients have the "display intranet sites in compatibility view" checkbox ticked. Which is precisely what I'm trying to override.

下面是我用来尝试理解IE如何决定实际触发兼容模式的文档。

The following is the documentation that I've used to try understand how IE decides to actually trigger the compatibility mode.

<一个href=\"http://msdn.microsoft.com/en-us/library/ff406036%28v=VS.85%29.aspx\">http://msdn.microsoft.com/en-us/library/ff406036%28v=VS.85%29.aspx

<一个href=\"http://blogs.msdn.com/b/ie/archive/2009/02/16/just-the-facts-recap-of-compatibility-view.aspx\">http://blogs.msdn.com/b/ie/archive/2009/02/16/just-the-facts-recap-of-compatibility-view.aspx

网站拥有者的始终处于其内容的控制权的网站所有者可以选择使用X-UA兼容的标签是绝对陈述了他们想要怎么样其网站显示,并绘制标准模式页面IE7标准。 的X UA兼容标签的使用替代兼容性视图在客户端上。

谷歌对于定义文档兼容性,可悲的是垃圾邮件引擎不会让我张贴超过2个网址。

Google for "Defining Document Compatibility", sadly the SPAM engine doesn't let me post more than 2 urls.

这是一个 ASP .NET Web应用程序,包括母版页上定义如下:

This is an ASP .NET web app and includes the following definitions on the master page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
   <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
</head>

的web.config

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <clear />
      <add name="X-UA-Compatible" value="IE=Edge" />
    </customHeaders>
  </httpProtocol>
</system.webServer>

我已经使用小提琴手来检查头部确实被正确注射。

I've used Fiddler to check that the header is indeed being injected correctly.

我的理解是,随着这些设置我应该能够覆盖浏览器设置了在兼容性视图中显示Intranet站点。但根据在客户端上我发现,有些人仍然会引发兼容模式。
它似乎也将下降到机器的水平,而策略组设置,因为我得到不同的结果,甚至当我用同一套在不同的客户端证书的使用。

My understanding is that with these settings I should be able override the "Display intranet sites in Compatibility View" browser setting. But depending on the client I've found that some of them will still trigger compatibility mode. It also seems to be down to the machine level rather a policy group setting, since I obtain different results even when I use with the same set of credentials on different clients.

禁用兼容性视图设置复选框的伎俩。但实际目的是为了确保应用程序呈现完全相同不管客户端设置方法相同。

Disabling the Compatibility View Settings checkbox does the trick. But the actual purpose is to make sure that the app is rendered exactly the same way regardless of the client settings.

有什么想法,我可能是什么可能缺少什么?是否有可能在所有强制IE总是渲染页面,而不会触发兼容模式?

Any thoughts and what I could be possibly missing? Is it possible at all to force IE to always render the pages without triggering Compat mode?

太感谢了。

PS:的网站目前正处于发展和当然不是微软的兼容性列表,但我也检查,以防万一。

PS: the site is currently in development and is of course not in Microsoft's compatibility list, but I've also checked just in case.

谷歌对于了解兼容性视图列表,可悲的是垃圾邮件引擎不会让我张贴超过2个网址。

Google for "Understanding the Compatibility View List", sadly the SPAM engine doesn't let me post more than 2 urls.

推荐答案

我发现这样做的两种常用方法的问题:

I found problems with the two common ways of doing this:


  1. 自定义页眉这样做(&LT; customHeaders&GT; )在web.config中允许同一应用程序的不同的部署到不同的有这一套。我认为这是一个更多可能出错的事情,所以我认为这是更好的,如果应用程序指定这code。此外, IIS6不支持此

  1. Doing this with custom headers (<customHeaders>) in web.config allows different deployments of the same application to have this set differently. I see this as one more thing that can go wrong, so I think it's better if the application specifies this in code. Also, IIS6 doesn't support this.

包括HTML &LT;&荟萃GT; 在Web窗体标签的母版页或MVC布局页面似乎比上面的好。但是,如果某些网页不从这些话继承标记需要被复制,所以有一个潜在的可维护性和可靠性问题。

Including an HTML <meta> tag in a Web Forms Master Page or MVC Layout Page seems better than the above. However, if some pages don't inherit from these then the tag needs to be duplicated, so there's a potential maintainability and reliability problem.

网络流量可能只发送 X-UA兼容头到Internet Explorer客户端被降低。

Network traffic could be reduced by only sending the X-UA-Compatible header to Internet Explorer clients.

如果您的应用程序中,导致所有页面,最终从一个根页面继承方式构造,包括&LT;元&gt;如所示标记的其他答案的。

Well-Structured Applications

If your application is structured in a way that causes all pages to ultimately inherit from a single root page, include the <meta> tag as shown in the other answers.

否则,
我认为,要做到这一点的最好办法是自动的HTTP标头添加到所有HTML响应。 做到这一点一种方法是使用 IHttpModule的

Otherwise, I think the best way to do this is to automatically add the HTTP header to all HTML responses. One way to do this is using an IHttpModule:

public class IeCompatibilityModeDisabler : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.PreSendRequestHeaders += (sender, e) => DisableCompatibilityModeIfApplicable();
    }

    private void DisableCompatibilityModeIfApplicable()
    {
        if (IsIe && IsPage)
            DisableCompatibilityMode();
    }

    private void DisableCompatibilityMode()
    {
        var response = Context.Response;
        response.AddHeader("X-UA-Compatible", "IE=edge");
    }

    private bool IsIe { get { return Context.Request.Browser.IsBrowser("IE"); } }

    private bool IsPage { get { return Context.Handler is Page; } }

    private HttpContext Context { get { return HttpContext.Current; } }

    public void Dispose() { }
}

IE =边缘表示,IE浏览器应使用其最新的渲染引擎(而不是兼容模式)来渲染页面。

IE=edge indicates that IE should use its latest rendering engine (rather than compatibility mode) to render the page.

似乎HTTP模块在web.config文件经常注册,但是这让我们回到第一个问题。但是,您可以将它们编程Global.asax中是这样的:

It seems that HTTP modules are often registered in the web.config file, but this brings us back to the first problem. However, you can register them programmatically in Global.asax like this:

public class Global : HttpApplication
{
    private static IeCompatibilityModeDisabler module;

    void Application_Start(object sender, EventArgs e)
    {
        module = new IeCompatibilityModeDisabler();
    }

    public override void Init()
    {
        base.Init();
        module.Init(this);
    }
}

请注意,这是非常重要的模块是静态初始化不实例,以便有只有一个例如每个应用程序。当然,在现实世界中的应用IoC容器也许应该管理这个。

Note that it is important that the module is static and not instantiated in Init so that there is only one instance per application. Of course, in a real-world application an IoC container should probably be managing this.


  • 在克服了这个答案的开始列出的问题。


  • 网站管理员没有对标头值的控制。这可能是一个问题,如果因特网浏览器的新版本出来并且不利地影响该网站的渲染。然而,这可以通过具有模块读取从应用程序的配置文件中的头值,而不是使用硬codeD价值可以克服的。

  • 这可能需要修改的ASP.NET MVC工作。

  • 这不是静态HTML页面的工作。

  • 在上述code中的 preSendRequestHeaders 事件似乎并没有在IIS6火灾。我还没有想出如何解决这个错误呢。

  • Website admins don't have control over the header value. This could be a problem if a new version of Internet Explorer comes out and adversely affects the rendering of the website. However, this could be overcome by having the module read the header value from the application's configuration file instead of using a hard-coded value.
  • This may require modification to work with ASP.NET MVC.
  • This doesn't work for static HTML pages.
  • The PreSendRequestHeaders event in the above code doesn't seem to fire in IIS6. I haven't figured out how to resolve this bug yet.

这篇关于如何有力地从服务器端设置IE的兼容模式了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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