On All Things Web

Apr 21

WURFL is a service used to detect mobile devices.  Stated on their web site, WURFL “is a Device Description Repository (DDR), i.e. a software component which contains the descriptions of thousands of mobile devices. In its simplest incarnation, WURFL is an XML configuration file plus a set of programming APIs to access the data in real-time environments.”

WURFL is used by various products, but can also be used directly in your web site.  If you are using .NET, whether web forms or MVC, you can get instructions on how to set it up here: http://wurfl.sourceforge.net/dotNet/

I had trouble getting the base installation to work correctly; I was getting a random error when it attempted to build the manager based on the configuration.  It was probably something I wasn’t doing,  so to quickly get support up and running, I chose to write my own wrapper around instantating of the manager.  Note that in this example, hard-coding the file strings was OK for me, since this was inside a web site and I was doing the same task over and over again.  If this was a reusable solution, passing these parameters in is preferred.

public class WurflDeviceManager
public const String WurflManagerCacheKey = “__WurflManager”;
public const String WurflDataFilePath = “~/App_Data/wurfl-latest.zip”;
public const String WurflPatchFilePath = “~/App_Data/web_browsers_patch.xml”;private static IWURFLManager CreateManager()
var wurflDataFile = HttpContext.Current.Server.MapPath(WurflDataFilePath);
var wurflPatchFile = HttpContext.Current.Server.MapPath(WurflPatchFilePath);
var configurer = new InMemoryConfigurer()
.PatchFile(wurflPatchFile);var manager = WURFLManagerBuilder.Build(configurer);
HttpContext.Current.Cache[WurflManagerCacheKey] = manager;

return manager;

public static IWURFLManager GetManager(HttpContextBase context)
var wurflManager = context.Cache[WurflManagerCacheKey] as IWURFLManager;

if (wurflManager == null)
wurflManager = CreateManager();

return wurflManager;

The approach I took was to provide a lazy load, checking from cache first if the object exists, then instantiating it and storing in cache if it doesn’t.  This way, the instance is always guaranteed to be present.

3 comments so far

  1. Chris Wright
    3:50 pm - 5-10-2012

    Hi. I run a couple of blogs and wanted to speak to you about yours. Can you email me so we can discuss properly. Thanks.

  2. James Rosewell
    3:53 pm - 7-17-2012

    I’ve just noticed this blog post. I’d like to correct something. 51Degrees.mobi does not use WURFL following the change to WURFL data licencing last year. An DDR maintained by 51Degrees.mobi which is optimised for performance and device detection accuracy is now used. The data is released under both the Mozilla Public Licence, and in a paid for premium form. Thanks. James

  3. Brian Mains
    2:45 am - 7-31-2012

    @James, I had read that somewhere, and should have looked into it more before making that statement. Thanks for the update. I corrected the post.

Leave a Reply

Your email address will not be published. Required fields are marked *