.NET Framework Class Library
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)
Syntax

Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class MobileCapabilities _
    Inherits HttpBrowserCapabilities
Visual Basic (Usage)
Dim instance As MobileCapabilities
C#
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class MobileCapabilities : HttpBrowserCapabilities
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class MobileCapabilities : public HttpBrowserCapabilities
JScript
public class MobileCapabilities extends HttpBrowserCapabilities
Remarks

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.

Examples

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.

C#
<%@ 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 = 
        (MobileCapabilities)Request.Browser;
    // Programatically find the mobile capabilities without using 
    // DeviceSpecific Filters.
    if(currentCapabilities.PreferredRenderingMIME=="text/html")
    {
        Label2.Text = "You are using an html supported device.";
    }
    else if(currentCapabilities.PreferredRenderingMIME == 
        "text/vnd.wap.wml")
    {
        Label2.Text = "You are using a wml supported device.";
    }
    Label1.Text = "Screen Width (chars): " + 
        currentCapabilities.ScreenCharactersWidth;
 }
 </script>
 <Mobile:Form runat="server" id=frmTemplate >
      <mobile:label ID="Label1" runat="server" />
      <mobile:label ID="Label2" runat="server" />
 </Mobile:Form>
.NET Framework Security

Inheritance Hierarchy

System..::.Object
  System.Web.Configuration..::.HttpCapabilitiesBase
    System.Web..::.HttpBrowserCapabilities
      System.Web.Mobile..::.MobileCapabilities
Thread Safety

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

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.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1
See Also

Reference

MobileCapabilities

Other Resources

Tags :


Page view tracker