IE9忽略了UserAgent的X-UA-Compatible标志

时间:2012-09-11 10:53:34

标签: internet-explorer cross-browser user-agent x-ua-compatible

我有一个互联网应用程序,因此IE9在兼容性视图中是默认的。我使用X-UA-Compatible标志。 我将它发送到HTTP标头和Meta-Tag。 IE9似乎接受它并使用IE9渲染引擎。但它仍然总是发送IE-7 UserAgent字符串。

有没有办法避免它,或者将IE9识别为非IE7浏览器?

我真的不想使用浏览器的白名单,而是使用不支持浏览器的黑名单(IE 5,6,7和8)。

我的例子:

我正在打开页面,因此IE9正在发送一个GET请求:

GET http://myserver/mypage/ HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg,     application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: de-CH
User-Agent: 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; Media Center PC 6.0; .NET4.0C; InfoPath.3; .NET4.0E)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: myserver
Cookie: MAKEBROWSERTEST=true

然后,我的服务器正在回答:

HTTP/1.1 302 Found
Cache-Control: private, no-cache="Set-Cookie"
Content-Type: text/html; charset=utf-8
Location: /myserver/mypage/two
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
Set-Cookie: MAKEBROWSERTEST=true; path=/
X-UA-Compatible: IE=edge
Date: Tue, 11 Sep 2012 10:04:21 GMT
Content-Length: 152

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/myserver/mypage/two">here</a>.</h2>
</body></html>

IE9正在重定向,但仍在发送MSIE 7.0用户代理:

GET http://myserver/mypage/two HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: de-CH
User-Agent: 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; Media Center PC 6.0; .NET4.0C; InfoPath.3; .NET4.0E)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: myserver
Cookie: MAKEBROWSERTEST=true

由于

1 个答案:

答案 0 :(得分:0)

我没有尝试重振旧线程,但如果有人遇到这个问题,他们可能会觉得这很有趣: Internet Explorer 11’s Many User-Agent Strings

  

如果用户选择在兼容性视图中呈现网站(单击工具&gt;兼容性视图设置),则IE将发送模仿Internet Explorer 7的UA 字符串的用户代理字符串:

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)

默认情况下,Intranet区域中的站点在兼容性视图中呈现,因此这是他们将看到的用户代理字符串。

所以我用IE9进行了测试:

在(正常模式下)你得到

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)

在兼容模式下,你得到

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; Media Center PC 6.0; .NET4.0C; .NET4.0E)