IE9正在忽略UserAgent的X-UA-Compatible标志



我有一个互联网应用程序,所以IE9默认在兼容性视图中。我使用X-UA-Compatible标志。我在HTTP头中发送了它,并将其作为元标记。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

感谢

我不想恢复一个旧线程,但如果有人遇到这个问题,他们可能会觉得很有趣:Internet Explorer 11的多用户代理字符串

如果用户选择在兼容性视图中呈现网站(单击"工具">"兼容性视图设置"),则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)

相关内容

最新更新