Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request.Browser.IsMobileDevice = false for Android, why?

I have samsung galaxy s2, in C# code it shows Request.Browser.IsMobileDevice = false, but I want to use mobile version for my application. How to have ability to show mobile version of my website, for Android devices?

Thank you, so much.

Sergey.

like image 293
Sergey Avatar asked Dec 01 '11 11:12

Sergey


3 Answers

You can check the User-Agent HTTP header.

The user-agent is an identifier that (usually) contains the browser name and version, as well as the name and version of the platform or OS the browser is running on. The current standard is to have this split into space-separated elements, but in reality the User-Agent field can be set to anything.

Example:

Mozilla/5.0 Windows NT 6.1 WOW64 rv 8.0 Gecko/20100101 Firefox/8.0

This shows that I'm running Firefox 8.0 (which uses Mozilla renderer v5.0 and Gecko layout engine release 2010/01/01) on a 64-bit version of Windows NT 6.1 Release (which is Windows 7).

You can get more info about user agent strings from here: http://www.useragentstring.com/

like image 64
Polynomial Avatar answered Nov 01 '22 13:11

Polynomial


Use 51Degrees.mobi from NuGet for a one click install with zero configuration which will correct this issue.

like image 40
James Rosewell Avatar answered Nov 01 '22 15:11

James Rosewell


You can create a file in App_Browsers with a regex to identify the browser, the following one is to firefox in Android:

<browsers>
    <!--Mozilla/5.0 (Android 5.0; Mobile; rv:44.0) Gecko/44.0 Firefox/44.0-->
    <browser id="FirefoxMobile" parentID="firefox3plus">
        <identification>
            <userAgent match="Mozilla.+\(Android.+Mobile.*\)" />
        </identification>
        <capabilities>
            <capability name="isMobileDevice" value="true" />
        </capabilities>
    </browser>
</browsers>
like image 22
Maykol Rypka Avatar answered Nov 01 '22 14:11

Maykol Rypka