65.9K
CodeProject is changing. Read more.
Home

Get Browser Information Using MobileCapabilities

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.56/5 (7 votes)

Jul 16, 2003

viewsIcon

49175

downloadIcon

444

Get browser information using MobileCapabilities.

Sample Image - browsercap.jpg

Introduction

ASP.NET provides an extensible mechanism for identifying a mobile client device, and for making the information available to the ASP.NET page framework and the ASP.NET mobile Web application. Like the HttpBrowserCapabilities class, the MobileCapabilities class provides information about the browser making the request. This article explains how you can display all capabilities using reflection, and how you can use them to customize your application for specific mobile devices.

Background

The MobileCapabilities class extends the HttpBrowserCapabilities class. The MobileCapabilities class offers a large number of read-only properties that provide type-safe access to the Browser object's capabilities dictionary.

You can use the Browser property of the HttpRequest object to point to an instance of a MobileCapabilities object, which can then be used to read the capabilities of the requesting browser and device.

Using the code

You can access a lot of information about the browser if your browser is correctly identified using <browsercap> section in machine.config.

// Define

System.Web.Mobile.MobileCapabilities currentCapabilities;
// Get MobileCapabilities from current Request.Browser

MobileCapabilities currentCapabilities = (MobileCapabilities)Request.Browser;
// get a property of the  browser 

string preferredRenderingMIME=currentCapabilities.PreferredRenderingMIME;

Sample code uses System.Reflection to display all properties of MobileCapabilities class.