17

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.

Sergey
  • 7,933
  • 16
  • 49
  • 77

4 Answers4

3

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/

Polynomial
  • 27,674
  • 12
  • 80
  • 107
2

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>
Maykol Rypka
  • 531
  • 6
  • 19
2

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

James Rosewell
  • 516
  • 3
  • 6
  • 8
    No longer an option. Well, it's an option, but you can't get updates without a premium data subscription. Crowdsourcing at it's finest! – Scott Silvi Sep 26 '12 at 19:33
0

Checking if the device is an Android one is useful.

There is a post with the code: http://dbarrowstechblog.blogspot.hk/2011/02/requestbrowserismobiledevice.html

Gabriel Chung
  • 1,527
  • 1
  • 18
  • 30
  • 1
    This is not ideal, as it will detect android tablets as mobile (and you generally don't want tablets to see a mobile version). User agent strings seem to very often contain "tablet" when they are tablets, so checking this as well will pretty much patch that up. – mike nelson Aug 01 '13 at 13:09