Search code examples
c#ihttphandlerhttpbrowsercapabilities

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.

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;
    }

Solution

  • The short answer is no. See SO for more detail, but HttpBrowserCapabilities is based on your framework update and what is stored in:

    %SystemRoot%\Microsoft.NET\Framework[version]\Config\Browsers

    Just be aware that the 51 Degrees library suggested currently has a severe design flaw. It raises an exception for each request when you are trying to detect whether a UA is mobile or not. We have discussed it with 51 Degrees and they will fix same in their 4.x release. Until then we have to live with:

    enter image description here

    You may have better luck with other 3rd party libraries.