Export (0) Print
Expand All

MobileCapabilities Class

Provides a single source for accessing capability information about a client device and for performing queries against device capabilities.

Namespace:  System.Web.Mobile
Assembly:  System.Web.Mobile (in System.Web.Mobile.dll)

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class MobileCapabilities : HttpBrowserCapabilities

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.

During the page load, the MobileCapabilities object obtains the capabilities through the Browser property as previously discussed. The PreferredRenderingMime and the ScreenCharactersWidth properties of the MobileCapabilities object report back to the browser by setting properties on the HttpResponse object and also by programmatically setting the Text property of certain controls on the page.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
    Language="c#" %>
<script language="c#" runat="server">
public void Page_Load(Object sender, EventArgs e)
    System.Web.Mobile.MobileCapabilities currentCapabilities;
    MobileCapabilities currentCapabilities = 
    // Programatically find the mobile capabilities without using 
    // DeviceSpecific Filters.
        Label2.Text = "You are using an html supported device.";
    else if(currentCapabilities.PreferredRenderingMIME == 
        Label2.Text = "You are using a wml supported device.";
    Label1.Text = "Screen Width (chars): " + 
 <Mobile:Form runat="server" id=frmTemplate >
      <mobile:label ID="Label1" runat="server" />
      <mobile:label ID="Label2" runat="server" />

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1

Community Additions

© 2015 Microsoft