简体   繁体   English

使用HttpBrowserCapabilities是OS和移动设备检测的最佳实践吗?

[英]Is using HttpBrowserCapabilities best Practice for OS and mobile detection?

I would like to know if using HttpBrowserCapablilties that i got from HttpContext.Request.Browser is the best way for me to check if the request is coming from a windows desktop machine and is not a mobile device. 我想知道是否使用从HttpContext.Request.Browser获得的HttpBrowserCapablilties是我检查请求是否来自Windows台式机而不是移动设备的最佳方法。

See below for example of how i am using it. 请参阅以下示例,了解我如何使用它。

public static bool IsWindowsDesktop(this HttpBrowserCapabilities browser)
    {
        return string.Equals(browser.Platform, "WinNT") && browser.IsMobileDevice;
    }

The short answer is no. 最简洁的答案是不。 See SO for more detail, but HttpBrowserCapabilities is based on your framework update and what is stored in: 有关更多详细信息,请参见SO 。但是HttpBrowserCapabilities基于您的框架更新以及存储在其中的内容:

%SystemRoot%\\Microsoft.NET\\Framework[version]\\Config\\Browsers %SYSTEMROOT%\\ Microsoft.NET \\框架[版] \\配置\\浏览器

Just be aware that the 51 Degrees library suggested currently has a severe design flaw. 请注意,目前建议的51度库存在严重的设计缺陷。 It raises an exception for each request when you are trying to detect whether a UA is mobile or not. 当您尝试检测UA是否可移动时,它将为每个请求引发一个异常。 We have discussed it with 51 Degrees and they will fix same in their 4.x release. 我们已经与51 Degrees进行了讨论,他们将在其4.x版本中修复该问题。 Until then we have to live with: 在此之前,我们必须与:

在此处输入图片说明

You may have better luck with other 3rd party libraries. 您可能会对其他第三方图书馆有更好的运气。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM