The default browser compatibilities mobile detection in ASP.NET in System.Web.HttpBrowserCapabilitiesBase is pretty poor. It ignores majority of the mobile devices and since it does not update on regular basis, it will ignore any new devices as well. Simply put, if you are using mobile-specific views then most mobile devices will get only the desktop views, because the device will be not recognised as a mobile device.

You can add browser definition files to your solution and specify capabilities for the latest devices. It is however a quick road to hell.

Instead, there are several open source libraries that help you improve the device detection and override the BrowserCapabilities. 51Degrees.mobi is widely recognised and I had very good experience using it in the past. It contains an amazing list of the devices which gets updated on regular basis. It is a freemium product, however, in most cases you will only need the functionality that is in the free version.

Add 51Degrees to your solution

blog-51Degrees-NugetThe easiest way to integrate 51Degrees is by adding a nuget package. The package name is 51Degrees.mobi and it brings down the FiftyOne.Foundation.dll, 51Degrees.mobi.config config file and /Mobile/Default.aspx page.

If you run .NET 4, the dll automatically registers its own MobileCapabilitiesProvider (HttpCapabilitiesBase.BrowserCapabilitiesProvider) using PreApplicationStartMethod attribute and registers the RedirectModule. If you are on 2.0 or 3.5, you will need to register the detection module yourself in your web.config.

<httpModules>
    <add name="Detector" type="FiftyOne.Foundation.Mobile.Detection.DetectorModule, FiftyOne.Foundation"/>
</httpModules>

OR

<system.webServer>
    <modules>
    <remove name="Detector"/>
    <add name="Detector" type="FiftyOne.Foundation.Mobile.Detection.DetectorModule, FiftyOne.Foundation"/>
    </modules>
</system.webServer>

 

Use Detector To Improve Mobile Detection

If all you want is improvement of your mobile detection, then you can safely delete the 51Degrees.mobi.config and the Default.aspx page. The 51Degrees MobileCapabilitiesProvider will still run and override your IsMobileDevice property. If you use mobile views, you will notice a significant improvement in which devices get the mobile view.

You should not forget that 51Degrees will regard all tablets as mobile devices. This will result in IPad getting served the mobile views.  If that’s something that you don’t want, you will need to write extra  filter that will reset the IsMobileDevice to false for all tablet devices.

Redirect Your Mobile Traffic

51Degrees can also be configured to redirect your mobile traffic using the 51Degrees.mobi.config file in the root of your app. It lets you define either page-by-page redirects or redirects based on patterns or regular expressions.

An example of the redirect setting

<redirect firstRequestOnly="true" timeout="20" devicesFile="~/App_Data/Devices.dat" mobilePagesRegex="/(Mobile|Tablet)/">
    <locations>
        <location name="tablet" url="~/Tablet/Default.aspx">
        <add property="IsTablet" matchExpression="true"/>
        <add property="IsMobile" matchExpression="true"/>
        </location>
        <location name="mobile" url="~/Mobile/Default.aspx">
        <add property="IsMobile" matchExpression="true"/>
        </location>
    </locations>
</redirect>

The sample above will catch the first request of the device and redirect it to either /Mobile/Default.aspx or /Tablet/Default.aspx based on the device features. If you are on premium, you can optionally specify your devices file. You can find out more about the redirect settings in the 51Degrees user guide.

What You Get For Your Money

If you decide to buy 51Degrees.mobi, it works out around $1 per day per site instance. You pay a subscription for a year, which gives you fully featured detection and regular updates. And what else do you get? Lots of detail – and I mean lots of it. Here’s a list of all the capabilities that 51Degrees offers – the premium only features are in red.

Related Links

51Degrees on Codeplex
What’s New In Asp.NET MVC 4 Mobile Development

12 Comments

  • James Rosewell said

    Thank you for the clear and concise blog post.

    The paid for product licencing also allows others to include the device data within their own solutions. DotNetNuke do this very effectively across there entire product range.

    James - CEO & Founder of 51Degrees.mobi

  • toms shoes girls said

    "One would have thought that an organisatoin of your size would have ceased to be interested in a blazer and a couple of pair of trousers after so long a time,"

  • louis vitton said

    The most recent visit is only the beginning of close study of Enceladus. Scientists will have another chance to observe Enceladus when Cassini passes very near the moon again in August.

  • retro jordans said

    Charles Lindbergh later wrote about being a new pilot. He said he felt different from people who never flew. "In flying," he said, "I tasted a wine of the gods of which people on the ground could know nothing."

  • louis vuitton shoes said

    You may not be able to avoid living in areas where it snows often. However, you can avoid becoming a victim of a snowstorm. Most people are told to stay in their homes until the storm has passed. When removing large amounts of snow, they should stop and rest often. Difficult physical activity during snow removal can cause a heart attack, especially among older adults.

  • lv said

    However, his parents died before the boy reached the age of eight. After that, he had to survive on subsidies from a Buddhist temple and lived there for more than 10 years.

  • celine dion youtube concert said

    Les nouveaux avions sont effectivement d茅tenus et exploit茅s par Republic Airways mais volent comme des jets r茅gionaux American Eagle avec le nouveau American Airlines peinture ext茅rieure emploi. Les plans de ferry largement passagers et de hubs am茅ricains, dont O est le deuxi猫me plus grand.

Add a Comment