locked
What is best way to determine (in asp.net) if device is mobile or desktop device? RRS feed

  • Question

  • User300685930 posted

    Trying to find the best way to determine if mobile device.

    Thursday, September 20, 2007 10:21 AM

Answers

All replies

  • User-1037848597 posted

     Hi Peter,

    The IsMobileDevice property is one way.

    http://forums.asp.net/p/1155270/1897491.aspx#1897491

     

     - Kiran
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 20, 2007 9:15 PM
  • User300685930 posted

    The IsMobileDevice property is one way.
     

     

    Have you used that tag and found it reliable?

     

    Thursday, September 20, 2007 11:44 PM
  • User1634317999 posted

    Hello Peter,

    if I use the very slow advanced search of this forum I get four pages with results for the term isMobileDevice, eight pages for the term detect and four pages for the term determine. RSS feeds for these results are also available.

    Friday, September 21, 2007 1:03 AM
  • User300685930 posted

    So, now I'm confused.  It seems that isMobileDevice is a property of the MobileCapabilities class in .net 1.1 but not .net 2.0.  when I look at the 2.0 doc, it shows this as the intro page (pasted below).  I am using 2.0 and above so 1.1 does not help me.  Am I missing something in all those pages of search results? 

    Also, not to desparage the speed of search on these forums, but I find that if I type forums.asp.net and my query into google, I get pretty good results.  I think they have these forums pretty well indexed.

    Thanks SKT_01 for your feedback so far.  Looking forward to more.

    -Peter

     

    <%@ 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>
    
    Friday, September 21, 2007 1:22 AM
  • User300685930 posted

    OK, now that I do a little more research, I see they moved it to the HttpBrowserCapabilities class.  When I run reflector on it, it ultimately calls CapsParseBoolDefault (which I'm pasting below from reflector).  Can anyone tell me how this makes it a mobile device?

    private bool CapsParseBoolDefault(string capsKey, bool defaultValue)
    {
        string str = this[capsKey];
        if (str == null)
        {
            return defaultValue;
        }
        try
        {
            return bool.Parse(str);
        }
        catch (FormatException)
        {
            return defaultValue;
        }
    }
    

     

    Friday, September 21, 2007 1:27 AM
  • User1634317999 posted

    So, now I'm confused.  It seems that isMobileDevice is a property of the MobileCapabilities class in .net 1.1 but not .net 2.0.  when I look at the 2.0 doc, it shows this as the intro page (pasted below).  I am using 2.0 and above so 1.1 does not help me.  Am I missing something in all those pages of search results? 

     

    If I take a look at the documentation of the .NET Framework with the MSDN Enhanced Search  I get the following link to the HttpCapabilitiesBase.IsMobileDevice Property.

    At the bottom of the IsMobileDevice property documentation page I click the link:

    Reference

    HttpCapabilitiesBase Class

    Result of the steps above:

    .NET Framework Class Library<!---->
    HttpCapabilitiesBase Class<!---->
    <!--Content type: DocStudio. Transform: devdiv2mtps.xslt.-->

    Provides access to detailed information about the capabilities of the client's browser.  

     

     


     

     

    Friday, September 21, 2007 2:20 AM