Understanding User-Agent Strings

本文介绍了Internet Explorer浏览器的用户代理字符串组成及解析方法。详细解释了兼容性标记、版本号和平台信息等字段,并展示了如何通过修改注册表来改变用户代理字符串。

Introduction
When you visit a Web page, your browser sends the user-agent string to the server hosting the site that you are visiting. This string indicates which browser you are using, its version number, and details about your system, such as operating system and version. The Web server can use this information to provide content that is tailored for your specific browser.
The following figure shows a sample user-agent string reported by Internet Explorer that highlights its tokens.

A typical Internet Explorer user-agent string.

For historical reasons, Internet Explorer identifies itself as a Mozilla 4.0 browser.

The sample user-agent string contains three tokens.

1.The Compatibility flag ("compatible") is used by most modern browsers. It indicates that Internet Explorer is compatible with a common set of features.

2.The Version token identifies the browser and contains the version number. The version token in the example ("MSIE 7.0") identifies Internet Explorer 7.

3.The Platform token identifies your operating system and contains the version number. The platform token in the example ("Windows NT 6.0") indicates Windows Vista.

In the example, Internet Explorer is the user agent. However, other programs also provide user-agent strings when contacting servers over the Internet. For example, the Windows RSS Platform provides the following user-agent header when requesting RSS data.

Windows - RSS - Platform / 1.0 (MSIE 7.0; Windows NT 5.1)

Like the user-agent string for Internet Explorer, this user-agent header provides details about your system.

Alternate tokens can appear in the user-agent string for a number of reasons; usually, they identify optional features installed on your system. For example, an "SV1" token appears in the user-agent string of a Windows XP user who has installed Windows XP Service Pack 2 (SP2). It is also important to note that certain non-Microsoft parties modify the user-agent string for their own purposes.

Note: To protect your privacy, you should periodically review your user-agent string and verify its contents.
User-Agent Registry Keys

When you install certain Windows components, such as the Microsoft .NET Framework or Windows XP SP2, tokens are added to the user-agent string. This is done by adding tokens to the following registry keys.

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
      SOFTWARE
           Microsoft
                Windows
                     CurrentVersion
                          Internet Settings
                               User Agent
                                    Pre Platform
                                         Token = Value
                                    Post Platform
                                         Token = Value

The Pre-Platform and Post-Platform keys contain values whose names appear before and after the Platform token, respectively. For example, if a string value is added to the Post-Platform key, the name appears after the platform token in the user-agent string. Multiple tokens added to either key appear in an unpredictable order.

You can also override certain tokens of the user-agent string by adding values to the following registry key.

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
      SOFTWARE
           Microsoft
                Windows
                     CurrentVersion
                          Internet Settings
                               5.0
                                    User Agent
                                        (default) = "Mozilla/4.0"
                                        Compatible = "compatible"
                                        Platform = "Windows NT 5.1"
                                        Version = "MSIE 6.0"
                                         Pre Platform
                                              Token = Value
                                         Post Platform
                                              Token = Value

我在Internet Settings\User Agent\Pre Platform下添加HelloPrePlatform,在Internet Settings\User Agent\Post Platform下添加HelloPostPlatform,在Internet Settings\5.0\User Agent\Pre Platform下添加Hello5.0PrePlatform,在Internet Settings\5.0\User Agent\Post Platform下添加Hello5.0PostPlatform,在Internet Settings\User Agent下添加HelloUserAgent,在Internet Settings\5.0\User Agent下添加Hello5.0UserAgent查看IE的useragent的结果是

HelloUserAgent
Mozilla/4.0 (compatible; MSIE 8.0; HelloPrePlatform; Windows NT 6.1; Trident/4.0; MS-OC 4.0; HelloPostPlatform; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; CIBA; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; Hello5.0PostPlatform)
italics tokens are all in Internet Settings\5.0\User Agent\Post Platform
How to detect Browser version with JavaScript

How to detect Browser version with C#(Silverlight)


Ref:http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx

转载于:https://www.cnblogs.com/whyandinside/archive/2009/08/12/1544181.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值