简体   繁体   English

在什么时候我需要添加X-UA兼容的元标记?

[英]At what point do I need to add the X-UA Compatible meta tags?

I'm trying to add X-UA Compatible meta tags to my .net project by overriding a page method but I'm not exactly sure at what stage I need to add the tags. 我试图通过覆盖页面方法将X-UA兼容的元标记添加到我的.net项目中,但是我不确定在什么阶段需要添加标记。 At the moment I have: 目前,我有:

    protected override void OnInit(EventArgs e)
    {
        HtmlMeta meta = new HtmlMeta();
        meta.HttpEquiv = "X-UA-Compatible";
        meta.Content = "IE=EmulateIE7";
        Page.Header.Controls.Add(meta);
        base.OnInit(e);
    }

but this doesn't appear to be working. 但这似乎不起作用。 Do I have to add the tags before the page has initialized? 页面初始化之前是否需要添加标签? On load? 负载? Any help would be appreciated. 任何帮助,将不胜感激。

I would do this via the web.config: 我可以通过web.config来做到这一点:

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

Will work and requires no changes to your code. 将正常工作,无需更改您的代码。

More information: http://www.iis.net/configreference/system.webserver/httpprotocol/customheaders 详细信息: http : //www.iis.net/configreference/system.webserver/httpprotocol/customheaders

Generally speaking, you should not add it. 一般来说,您不应该添加它。 Please check the relevant MSDN article about specifying document models. 请查看有关指定文档模型的相关MSDN文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM