Thursday, 14 June 2012

ASP.NET Browser Definition File for Android (android.browser)

Automate your network audit and documentation

When trying to use the Request.Browser.IsMobileDevice property in ASP.NET you may be disappointed to see it return false even when using a mobile device such as an iPhone. This is because ASP.NET relies on browser definition files (with an extension of .Browser) such as iPhone.browser to detect the capabilities of a remote browser.

Though there are a number of more advanced solutions than Browser definition files they are still useful in simple situations.

Codeplex has an update of the browser definition files that came with ASP.NET 4 however these do not include a browser definition file for Android devices.

The following should provide some help - just save to the App_Browsers directory as Android.browser.

The following is the output from some ASP.NET sample code

Is Mobile Device: True
Browser: Android
Browser: ID android
Browser: Version 4.0.4

  <!--Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; sdk Build/MR1) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30-->
  <browser id="Android" parentID="safari1plus">
      <userAgent match="Android.(?'version'(?'major'\d+)(?'minor'\.\d+)(?'build'\.\d+))\w*" />
      <capability name="browser"                        value="Android" />
      <capability name="majorVersion"                   value="${major}" />
      <capability name="minorVersion"                   value="${minor}" />
      <capability name="version"                        value="${version}" />
      <capability name="type"           value="Android${major}" />
      <capability name="platform" value="Android" />
      <capability name="mobileDeviceManufacturer"       value="Google" />
      <capability name="activeXControls"                value="false" />
      <capability name="backgroundSounds"               value="false" />
      <capability name="beta"                           value="false" />
      <capability name="canSendMail"                    value="false" />
      <capability name="cookies"                        value="true" />
      <capability name="frames"                         value="false" />
      <capability name="isColor"                        value="true" />
      <capability name="isMobileDevice"                 value="true" />

No comments:

Post a Comment