Overview

Here you'll find a technical overview of the logic used in the 51Degrees Foundation solution for .NET. It covers the process used to determine whether a mobile device is making a request to your web site and how this information is used to redirect to a mobile-specific landing page.

HTTP Headers

Every browser, either mobile or traditional, will send a string that identifies itself when accessing a web site. This string is called the UserAgent and is transmitted in the header fields of the HTTP request. In .NET the UserAgent string is accessible via the UserAgent property of the HttpRequest object. 51Degrees Foundation takes the UserAgent string as the primary method of identifying the mobile device, browser and associated capabilities. The most important capability to determine is the mark-up supported so a page can be rendered in the correct format.

Some mobile devices, such as Samsung, Nokia and BlackBerry, or the Opera browser will send an additional field usually called x-wap-profile or Device-Stock-UA that tends to be unique to the type of device. When this field is present, 51Degrees Foundation uses it to improve device detection accuracy and performance.

Device Databases

A database of mobile devices with UserAgent as a primary key is needed to determine capabilities not contained in the request header. 51Degrees provides three versions of mobile device data: the free Lite version and paid-for Premium and Enterprise version that include more device properties and is updated more frequently. Both files are provided as an efficient binary format optimised for the APIs.

The 51Degrees device database contains a vast number of useragents and their associated hardware, software and browser. The Foundation employs a variety of techniques to match the UserAgent provided by the requesting browser to a device held in the mobile database.

When the 'worker' process is initiated a single instance of the detection provider is created. Depending on configuration all the data can be loaded into memory, or the data can be retained on disk and only loaded when required. Loading data into memory results in faster device detection at the expense of main memory usage. During device matching, a large amount of data needs to be searched rapidly to return devices and capabilities. 51Degrees Foundation is written specifically to complete these tasks as quickly as possible using the smallest amount of memory. It will perform significantly faster than a generic data storage solution using a database.

Processing Page Requests

Every HTTP request received by a .NET web site has a browser object associated with it to provide information about the browser making the request. The browser object is of the HttpBrowserCapabilities class and is accessed via the 'Request objects' browser property. The standard .NET deployment from Microsoft contains little specific information about different browsers and devices, which means the browser object is of limited benefit for a mobile web site targeting a wide variety of mobile devices. 51Degrees enhances the browser object, making it significantly more useful when developing mobile web sites and applications. When a new request is received, the device making the request is determined from the UserAgent string and the device database. The capabilities already provided by .NET are enhanced with the capabilities found for the device in the database.

Matching Devices

When a HTTP request is received, 51Degrees must find a matching device from the database. The logic used to achieve this is shared across other implementation and is fully described in the how device detection works pages.

Detecting Mobile Pages

When a request is received by ASP.NET, an HttpHandler is assigned to process it and provide a response. 51Degrees intercepts request processing after the HttpHandler has been assigned but before the handler has started to do any processing. If the handler is not for a mobile page and the device is a mobile device, the request will be redirected. This precise behaviour can be altered via settings in the web.config file.

If you'd like to know more, please download the project or have a look at our forum.