Click here to Skip to main content
Click here to Skip to main content

ASP.NET Mobile Device Detection with Additional Methods

By , 30 Oct 2011
 

Introduction

In ASP.NET, you can easily detect the mobile device request using Request.Browser.IsMobileDevice  property and Request.UserAgent.But these functionalities don't work all the time, so to get the more appropriate results for the mobile detection and want to get more details about the mobile, the WURFL.dll is more useful.

Background

Some of the popular mobile devices/browsers won’t be detected using this way because ASP.NET browser files are not supported in Opera Mobile or Android devices. That means if you want to classify the desktop page and mobile page, it won't helps you out.

Using the Code

  1. Add the WURFL.dll reference to your project.
  2. Copy the App_Data files to your project App_Data folder.
  3. Copy & Paste the WurflLoader.cs file to your App_Code folder.
  4. Build the project and now you can try the sample page WebForm1.aspx in browser.
	//
	// The sample Method to check weather the device is a mobile and not a tablet.
	//
public static Boolean isMobile()
{
   var device = WurflLoader.GetManager().GetDeviceForRequest(HttpContext.Current.Request);
   if (Convert.ToBoolean(device.GetCapability("is_wireless_device")) && !Convert.ToBoolean(device.GetCapability("is_tablet")))
  {
     return true;
  }
  else
  {
     return false;
  }
}

Points of Interest

If there is a need of mobile browser detection and classification of mobiles needed, then this will be very useful. This is an open standard DLL.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

manuscrazy
Software Developer (Senior) Ray Business Technologies Pvt. Ltd.
India India
Member
Senior software engineer (Hyderabad,India)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
SuggestionDevice detection in multiple languages. [modified]memberJMatthewson18 Sep '12 - 4:10 
If you're looking for some open source code which fulfills a similar purpose, check out 51Degrees.mobi. I'm doing some work for them on their open source C solution, but they also have solutions implemented for Java, ASP.NET and PHP.

modified 18 Sep '12 - 10:19.

SuggestionThis is NOT a one stop solution!!memberD Becker3 Nov '11 - 4:03 
I downloaded this project because it does what I need and looked simple to use. Which in fairness it is, but beware, before you can get this working you will need to download other libraries.
 
If like me, you are the type to read pages before just hitting the download link, then make sure you have a bit of time spare because you will also need:
 
ICSharpCode.SharpZipLib (http://www.icsharpcode.net/opensource/sharpziplib/[^]
log4Net http://archive.apache.org/dist/incubator/log4net/1.2.10/[^]
 

The libraries are referenced by the library in this project so you have to have them (note 1.2.10.0 of log4net is out of date and is a framework 2 build).
 
Neither of these libraries are required for mobile phone devices, they are merely personal preferneces of the author. Can I suggest a 'clean' version this project with native compressed file handling and no logging?
GeneralRe: This is NOT a one stop solution!!membermanuscrazy3 Nov '11 - 20:27 
Thanks for the comments. Please create a clean solution.
manu

GeneralRe: This is NOT a one stop solution!!memberD Becker3 Nov '11 - 23:22 
After a lot of trawling yesterday, I found this:
 
"To enable WURFL on your application you need to download the WURFL binaries and data. Binaries include wurfl.dll and a couple of dependencies such as log4net.dll and ICSharpCode.SharpZipLib.dll. The wurfl.dll file must be added as a reference to your project." from http://wurfl.sourceforge.net/dotNet/[^]
 
I'll be looking at the Wurfl API to see if I can produce a nice clean solution.
 

Manu, I may have alluded to the extra binaries being your fault, which it isn't, so apologies.
QuestionWURFL is not so open anymorememberDoug D in NH2 Nov '11 - 5:13 
Be sure to carefully read the WURFL license.
http://wurfl.sourceforge.net/licence.php

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 30 Oct 2011
Article Copyright 2011 by manuscrazy
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid