HttpBrowserCapability 缺少一些信息?

发布于 2024-11-06 09:20:18 字数 412 浏览 6 评论 0原文

我想使用 Request.Browser 属性(HttpBrowserCapability 类)来确定客户端系统的某些属性。

然而我似乎遇到了这个课程的一些限制。我找不到一些应该相对容易从 UserAgent 字符串中解析的属性,例如操作系统版本(对于大多数 Windows 版本,Platform 只会返回 WinNT,但不会Vista、XP 等)或是否为 x64(仅限 Win16Win32 属性)。

我本希望在 HttpBrowserCapability 类中看到这些属性,因为大多数其他用户代理信息都在那里。我错过了什么吗?我可以在其他地方找到此信息吗?或者我应该自己从 UserAgent 字符串中解析它?

I'd like to use the Request.Browser property (HttpBrowserCapabilities class) to determine some properties of the client's system.

However I seem to run into some limitations of this class. I can't find some properties that should be relatively easy to parse from the UserAgent string, like the OS version (Platform will only return WinNT for most Windows versions, but not Vista, XP, etc.) or whether it's x64 or not (only Win16 and Win32 properties).

I would have expected to see these properties in the HttpBrowserCapabilities class, because most other user agent information is there. Am I missing something? Can I find this information somewhere else? Or should I just parse it from the UserAgent string myself?

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

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

发布评论

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

评论(2

窝囊感情。 2024-11-13 09:20:18

browserCaps 元素在 ASP.NET 2.0 及更高版本中已弃用。除非您使用 .NET 1 或 1.1,否则应改用浏览器定义文件。

将 *App_Browsers* 文件夹添加到您的网站(如果尚不存在),然后创建一个名为“Platforms.browser”的新文件。 (名称并不重要;只需扩展名即可。)

打开新的 .browser 文件并粘贴以下内容:

<browsers>
    <gateway id="PlatformWinVista" parentID="PlatformWinnt">
        <identification>
            <userAgent match="Windows NT 6\.0" />
        </identification>
        <capabilities>
            <capability name="platform" value="Windows Vista" />
        </capabilities>
    </gateway>

    <gateway id="PlatformWin7" parentID="PlatformWinnt">
        <identification>
            <userAgent match="Windows NT 6\.1" />
        </identification>
        <capabilities>
            <capability name="platform" value="Windows 7" />
        </capabilities>
    </gateway>
</browsers>

您可能需要触发站点的重新编译以使新文件生效。

注意:这些节点必须是网关节点而不是浏览器节点。如果您尝试将它们创建为浏览器节点,您将获得一个 网站重新编译时出现解析器错误

The browserCaps element is deprecated in ASP.NET 2.0 and higher. Unless you're using .NET 1 or 1.1, you should use a browser definition file instead.

Add the *App_Browsers* folder to your site, if it doesn't already exist, and create a new file called "Platforms.browser". (The name doesn't matter; only the extension.)

Open the new .browser file and paste in the following:

<browsers>
    <gateway id="PlatformWinVista" parentID="PlatformWinnt">
        <identification>
            <userAgent match="Windows NT 6\.0" />
        </identification>
        <capabilities>
            <capability name="platform" value="Windows Vista" />
        </capabilities>
    </gateway>

    <gateway id="PlatformWin7" parentID="PlatformWinnt">
        <identification>
            <userAgent match="Windows NT 6\.1" />
        </identification>
        <capabilities>
            <capability name="platform" value="Windows 7" />
        </capabilities>
    </gateway>
</browsers>

You might need to trigger a recompilation of the site for the new file to take effect.

NB: These nodes have to be gateway nodes rather than browser nodes. If you try to create them as browser nodes, you'll get a parser error when your site recompiles.

梨涡 2024-11-13 09:20:18

您可以通过在 machine.config/web.config 文件中添加/扩展 browserCaps 配置部分来扩展 HttpBrowserCapability。例如,要更准确地检测操作系统版本,请在配置文件中添加如下内容:

<system.web>
    <browserCaps>
      <use var="HTTP_USER_AGENT" />
      <filter>
        <case match="Windows NT 6.1">
          platform=Windows7
        </case>
      </filter>
    </browserCaps>
  </system.web>

如果您使用在 Windows 7 上运行的 Mozilla 访问网站 (UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0. 1) Gecko/20100101 Firefox/4.0.1") 您会看到Request.Browser.Platform 将显示“Windows7”。有关详细信息,请参阅此处:http://msdn .microsoft.com/en-us/library/sk9az15a%28v=vs.71%29.aspx

在 browserCaps 部分添加正则表达式以匹配WOW64 字符串,以便检测客户端平台是否为 64 位(我不确定对于在 64 位上运行的非 Windows 平台,WOW64 等效项是什么)。

...当然,通过在元素中使用正则表达式,您除了自己实际解析 UserAgent 字符串之外什么也不做。但是,您可以轻松地在网络上找到预定义的 browserCaps(例如 http://owenbrady.net/browsercaps/CodeProject.xml )。

请记住,尽管此功能非常强大,但它仍然不是 100% 准确。例如,Windows 7 和 Windows Server 2008 R2 都将返回 Windows NT 6.1 作为平台。

You can extend the HttpBrowserCapabilities by adding/extending the browserCaps configuration section in your machine.config/web.config file. For example, to detect the OS version more accurately, add something like this to your config file:

<system.web>
    <browserCaps>
      <use var="HTTP_USER_AGENT" />
      <filter>
        <case match="Windows NT 6.1">
          platform=Windows7
        </case>
      </filter>
    </browserCaps>
  </system.web>

If you access the web site with Mozilla running on windows 7 (UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1") you'll see that Request.Browser.Platform will display "Windows7". See here for more information: http://msdn.microsoft.com/en-us/library/sk9az15a%28v=vs.71%29.aspx

Add a regex in the browserCaps section to match the WOW64 string in order to detect whether the client platform is 64 bit (I'm not sure what the WOW64-equivalent is for non-Windows platforms running on 64 bit).

...Of course, by using a regex in the element you're doing nothing else than actually parsing the UserAgent string yourself. However you can easily find predefined browseCaps on the web (e.g. http://owenbrady.net/browsercaps/CodeProject.xml).

Keep in mind that even though this capability is quite powerful, it still is not 100% accurate. For example, both Windows 7 and Windows Server 2008 R2 will return Windows NT 6.1 as the platform.

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