HTTP_USER_AGENT 和 navigator.userAgent 不一样,有什么想法吗?

发布于 2025-01-01 08:04:53 字数 570 浏览 1 评论 0原文

我在客户端使用 Javascript,获取 navigator.userAgent,返回:

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; HPNTDF; .NET4.0C; .NET4.0E)

使用 C# Request.ServerVariables["HTTP_USER_AGENT"],返回:

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

如您所见,它的 IE :(。

IE总是这样,还是只有我这样? 如何获得相同的值?

PS,我什至在本地 IIS 中尝试过此操作,结果相同

I use Javascript in client, get navigator.userAgent, returns:

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; HPNTDF; .NET4.0C; .NET4.0E)

use C# Request.ServerVariables["HTTP_USER_AGENT"], returns:

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

As you can see, its IE :(.

IE always do this, or just me?
How to get the same value?

PS, I tried this even in local IIS, same results

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏有森光若流苏 2025-01-08 08:04:53

Internet Explorer 9 及更高版本中的用户代理字符串在 HTTP 请求中发送的版本与通过 navigator.userAgent 获取的版本之间几乎总是不同。这是因为字符串中所谓的特征标记。其背景解释如下:http:// /msdn.microsoft.com/en-us/library/ms537503%28v=vs.85%29.aspx

来自 msdn 文档:

早期版本的 Internet Explorer 包含在 HTTP 协商过程中使用用户代理字符串的前平台和后平台密钥部分定义的功能令牌。随着时间的推移,这会导致用户代理字符串过长,进而给某些 Web 服务器带来问题。当用户代理字符串超过 256 个字符时,通常会出现问题。从 Internet Explorer 9 开始,用户代理字符串在 HTTP 协商期间不再包含功能令牌。功能标记包含在导航器对象的 userAgent 属性返回的值中。依赖于早期行为的应用程序应进行相应修改。

您必须决定要在应用程序中使用哪一个。没有办法“同步”它们。通过 Javascript 获得的应该包含更多信息......

The user agent string in Internet Explorer nine and higher will almost always differ, between the version send in the HTTP request and the one obtained via navigator.userAgent. This is because of the so called feature tokens in the string. The background for this is explained here: http://msdn.microsoft.com/en-us/library/ms537503%28v=vs.85%29.aspx

From the msdn-document:

Earlier versions of Internet Explorer included feature tokens defined using the Pre-Platform and Post-Platform keys part of the user-agent string during the HTTP negotiation process. Over time, this lead to overly long user-agent strings, which in turn created problems for certain web servers. Problems usually appeared when user-agent strings were longer than 256 characters. As of Internet Explorer 9, the user-agent string no longer includes feature tokens during HTTP negotiation. Feature tokens are included in the value returned by the userAgent property of the navigator object. Applications that rely on the earlier behavior should be modified accordingly.

You must decide witch one you want to use in your application. There is no way to "synchronize" them. The one obtained via Javascript should contain more information...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文