2

我有一個互聯網應用程序,所以IE9默認在兼容性視圖中。我使用X-UA-Compatible標誌。 我發送它在HTTP頭和元標籤。 IE9似乎接受它並使用IE9渲染引擎。但它仍然始終發送IE-7 UserAgent字符串。IE9忽略UserAgent的X-UA兼容標誌

有什麼辦法可以避免它,或將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 

感謝

+0

其實IE渲染根據X頁-UA兼容設置。它只需按照用戶的要求通過請求IE7頁面,但在收到X-UA兼容後,它就像標籤所要求的那樣工作。 Jut嘗試在控制檯中使用'JSON'(女巫在IE7模式下不可用),你會看到這個功能。 –

+0

這是真的!對於渲染,它看起來在X-UA兼容設置上,但不在用戶代理字符串中,即使在我之前發送X-UA兼容標誌時也是如此。這對我來說很重要,因爲我想根據瀏覽器版本發出302請求!目前我看不到這樣做! – Lux

+0

也許你可以根據三叉戟版本做出一些假設。看起來它與瀏覽器版本一致。 –

回答

0

我不是試着把一個古老的線程,但如果有人遇到這一點,他們可能會發現這個有趣的: Internet Explorer 11’s Many User-Agent Strings

如果用戶選擇呈現在兼容性視圖站點(單擊工具>兼容性視圖設置),那麼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)