的HttpBrowserCapabilities丢失一些信息? [英] HttpBrowserCapabilities missing some information?

查看:355
本文介绍了的HttpBrowserCapabilities丢失一些信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的Request.Browser 财产(的HttpBrowserCapabilities 类<$ C C $>)确定的某些属性客户端的系统。

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

不过,我似乎碰到此类的一些限制。我无法找到某些属性,应该是比较容易从的UserAgent 解析的字符串,如操作系统版本(平台只返回WINNT对于大多数Windows版本,而不是Vista,XP等),或者它是否是64位或不(仅 Win16的 Win32的属性)。

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).

我本来期望在的HttpBrowserCapabilities 类,看看这些属性,因为其他大多数用户代理信息是存在的。我失去了一些东西?我能找到这些信息在其他地方?或者我应该只是解析它从用户代理字符串自己?

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?

推荐答案

您可以通过添加/扩展你的machine.config中/ web.config文件中的browserCaps配置部分延伸的HttpBrowserCapabilities。例如,为了更准确地检测操作系统的版本,增加一些像这样的配置文件:

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>

如果您访问与在Windows 7上运行Mozilla的网站(用户代理=Mozilla的/ 5.0(Windows NT的6.1; WOW64; RV:2.0.1)的Gecko / 20100101火狐/ 4.0.1),你会看到, Request.Browser.Platform会显示Windows7的。在这里看到更多的信息:的http:// MSDN .microsoft.com / EN-US /库/ sk9az15a%28V = vs.71%29.aspx

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

添加一个正则表达式中的browserCaps节进行到WOW64字符串匹配以检测客户端平台是64位(我不知道该WOW64相当于是在64位上运行非Windows平台的)。

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).

......当然,在你做的没有别的比实际解析用户代理字符串自己的元素使用正则表达式。但是你可以很容易地找到predefined browseCaps在网络上(如 http://owenbrady.net /browsercaps/$c$cProject.xml )。

...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).

请记住,即使这个功能是相当强大的,它仍然不是100%准确。例如,在Windows 7和Windows Server 2008 R2将返回的Windows NT 6.1的平台。

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.

这篇关于的HttpBrowserCapabilities丢失一些信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆