Welcome to Idea R | Branding - Web Agency - Digital Strategies
Switch to the mobile layout

      Idea R - Plan your visual communication at 360°
  • HomeHome
  • About UsAbout Us
  • ContactsContacts

Blog

Take a software geek from the 80s, add a new generation graphic designer and dilute with a longtime marketing strategist. Shake vigorously and you'll get the Idea R's blog.

Change language... italiano

You may be interested in

A infographic sample with ASP.NET

A infographic sample with ASP.NET

Let's try to create a simple infographic in ASP.NET starting from an XML file containing data about the carbon dioxide emissions in Europe.

Style sheets caching problems

Microsoft IIS caches all the style sheets that are placed inside the ASP.NET App_Themes folder, but there's a big problem...

Last published

Case study: branding and marketing for a magician

Case study: branding and marketing for a magician

Singular case study in the world of illusionism. See how we have created a brand and a web marketing campaign with exceptional results.

Can engineering industry sponsor art without going off topic?

How to design a page in an exhibition catalog of Biennale in Venice, for a customer who apparently has nothing to do with art.

Most popular

Lazy loading and the SEO problem, solved!

Lazy loading and the SEO problem, solved!

The best SEO solution to index your dynamically loaded contents, no more compromises!

Case study: TAV Engineering, branding for B2B services

How to create a brand that keeps distance from the cold and aseptic image of the metal industry, focusing instead on the human aspect.

Editor's pick

Mental marketing secret #1: the fake compromise

Mental marketing secret #1: the fake compromise

Can mentalism influence marketing? As a marketing professional and a long term magician, I will reveal you some tricks.

How to dramatically increase social media LIKEs to your web site

Here's a free download that I created some time ago. It's a good tool for increasing engagement, but use with caution.
newsletter

Stay informed on digital strategies

My reviews on the subject...

I have many books on web design, the list is quite long, especially if I have to include all those which deal strictly to programming. I shall therefore refer you to some interesting texts. Don't Make Me Think! is the most famous book on usability, you can not miss it if you're involved in web design.

RSS feed

3 methods to detect mobile devices in ASP.NET

Published on 11/14/2012
Categories: Web Design
3 methods to detect mobile devices in ASP.NET

Redirecting mobile visitors to the mobile version of your site, is a common task.
How to detect them in ASP.NET?

Solution 1: the native ASP.NET method

The HttpBrowserCapabilitiesBase class exposes the IsMobileDevice property, that seems to be the solution to our problem.
Unfortunately the property returns highly inaccurate values, due to the very basic parsing of the browser user agent.

Solution 2: 51Degrees.mobi

This open source library does a good job, you can install it using NuGet or directly from the 51Degrees project site.
When you install this free component, it comes along with with a data file that contains all the detailed user agents information of all the mobile phones in the market.
The only thing you have to do, is to periodically refresh this data file.

From a programmers prospective, you can configure an automatic redirection directly using configuration parameters in your config file, or you can manually test the extended HttpBrowserCapabilitiesBase.IsMobileDevice property that now return accurate results.

But there's a problem!

If you have to distinguish between smartphones and tablets, with this solution you can't or better, you can if you switch to the premium paid version.

Until 51Degrees version 1.x this was possible because the component was based on the WURFL database (Wireless Universal Resource FiLe), but with the new 2.x versions this changed as stated inside the official documentation:

The detection element replaces the wurfl element used in previous versions of the Foundation (v0.x, v1.x). Due to licencing changes from ScientiaMobile, the 51Degrees.mobi Foundation no longer supports WURFL data and instead uses 51Degrees.mobi Device Data.

Solution 3: WURFL

WURFL (Wireless Universal Resource FiLe) is deployed by key Internet companies such as Facebook and Google and it is the most used solution worldwide.
It can be easily included in your project using NuGet, but it has not a drag'n'drop implementation like 51Degrees, you have to code a little bit.

It is a two step process. First load the devices database and cache it for future use (you can do this in the Application_Start method).

using WURFL;
using WURFL.Aspnet.Extensions.Config;

...

// Try to load the WURFL manager from the cache
IWURFLManager wurflManager = (IWURFLManager)HttpContext.Current.Cache[WurflManagerCacheKey];
if (wurflManager == null)
{
    ApplicationConfigurer configurer = new ApplicationConfigurer();
    wurflManager = WURFLManagerBuilder.Build(configurer);
    // ...store the data file in the cache
    HttpContext.Current.Cache.Insert(WurflManagerCacheKey, wurflManager, null,
        DateTime.Now.AddMonths(1), Cache.NoSlidingExpiration);
}

When a page is requested the second step is to verify if the visitor is using a smartphone:

using WURFL;
using WURFL.Aspnet.Extensions.Config;

...

IDevice device = wurflManager.GetDeviceForRequest(Request.UserAgent);
// ...do not consider tablets as mobile devices (they have a wider display)
Boolean smartphone = String.Compare(device.GetCapability("is_wireless_device"), true.ToString(), true) == 0 && String.Compare(device.GetCapability("is_tablet"), false.ToString(), true) == 0;
if (smartphone)
    // ...redirect to the mobile version of your site

Did you find this article useful?

Please help us to spread it over the web using Google+.
You have only to press the button here below!

 

You are the reader number 6,087.

Comments

comments powered by Disqus
Creative Commons License

Photographies, videos, graphics and texts by Idea R are licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Previous article

Previous article

jQuery: how to throw and handle custom events

Next article

Infographic: the Social Media history

Next article
  • Visual Communication, Art DirectionVisual Communication, Art Direction
  • Apps, Cloud, Mobile, Software DesignApps, Cloud, Mobile, Software Design
  • Digital StrategiesDigital Strategies
  • BlogBlog
Touching finger
RSS feed
Blog

Scroll to top