Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我需要在什么时候添加与X-UA兼容的元标记?_C#_.net_Meta_X Ua Compatible - Fatal编程技术网

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

C# 我需要在什么时候添加与X-UA兼容的元标记?,c#,.net,meta,x-ua-compatible,C#,.net,Meta,X Ua Compatible,我正试图通过重写一个页面方法将与X-UA兼容的元标记添加到我的.net项目中,但我不确定在什么阶段需要添加这些标记。目前我有: protected override void OnInit(EventArgs e) { HtmlMeta meta = new HtmlMeta(); meta.HttpEquiv = "X-UA-Compatible"; meta.Content = "IE=EmulateIE7";

我正试图通过重写一个页面方法将与X-UA兼容的元标记添加到我的.net项目中,但我不确定在什么阶段需要添加这些标记。目前我有:

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

但这似乎不起作用。我必须在页面初始化之前添加标签吗?装载?任何帮助都将不胜感激。

我将通过web.config:

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


一般来说,您不应该添加它。
请查看有关指定文档型号的信息。

您好,谢谢您的回复,但这似乎不起作用。网站不会自动以兼容模式显示。您是否检查了返回的标题?您应该能够使用浏览器中“开发工具”中的“网络”选项卡执行此操作。或者使用一些先进的工具,比如Fiddler。