X-UA-Compatible在C#WebBrowser控件中不起作用

时间:2013-06-28 09:51:25

标签: c# winforms internet-explorer ie8-compatibility-mode

我在winforms WebBrowser控件中加载了网页。该页面需要以IE8模式呈现,因此我将X-UA-Compatible设置为IE=8

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" >
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="PRAGMA" content="NO-CACHE" />

不幸的是,当我检查用户代理时,我仍然有MSIE 7.0。 X-UA-Compatible被忽略的原因是什么?当我在IE9中直接打开我的页面时,一切都很好 - 文档模式切换到IE8。

我的用户代理:

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3)

1 个答案:

答案 0 :(得分:0)

“X-UA-Compatible”仅影响WebBrowser控件内容模式,但不影响它将发送的UserAgent标头。 (见https://blogs.msdn.microsoft.com/patricka/2015/01/12/controlling-webbrowser-control-compatibility/

此外,UserAgent标头是HTTP请求的一部分,在服务器开始发送响应时已经传输,包括任何“X-UA兼容”值。