locked
HOW to detect mobile web browser ? RRS feed

  • Question

  • User-845805365 posted

    Hi all,

    i am using Wan HTC Touch with windows 6.0 OS.

    my aim is to find the IPAddress of the mobile, Browser detection and device detection.

    using the code below i managed to display some details. i hosted this in my localmachines IIS

    protected void Page_Load(object sender, EventArgs e)
        {
            
            string ip=string.Empty;
           
            if (Request.Headers["User-Agent"] != null && (Request.Browser["IsMobileDevice"] == "true" || Request.Browser["BlackBerry"] == "true" || Request.UserAgent.ToUpper().Contains("MIDP") || Request.UserAgent.ToUpper().Contains("CLDC")) || Request.UserAgent.ToLower().Contains("iphone"))
            {
                            
                ip = Request.ServerVariables["REMOTE_ADDR"];
               }
                MobileCapabilities cap = (MobileCapabilities)Request.Browser;
    
               string agent = Request.UserAgent.ToString();
               string def = "User Agent :"+agent+"\nBrowser Type   :   " + cap.Type + "\n"
                           + "MajorVersion  :   " + cap.MajorVersion + "\n"
                           + "MinorVersion  :   " + cap.MinorVersion + "\n"
                           + "Platform      :   " + cap.Platform + "\n"
                           + "Browser       :   " + cap.Browser + "\n"
                           + "Version       :   " + cap.Version + "\n"
                           + "IsBeta ?      :   " + cap.Beta + "\n"
                           + "Is Crawler ?  :   " + cap.Crawler + "\n"
                           + "Is AOL ?      :   " + cap.AOL + "\n"
                           + "Is Win16 ?    :   " + cap.Win16 + "\n"
                           + "Is Win32 ?    :   " + cap.Win32 + "\n"
                           + "Supt Frames ? :   " + cap.Frames + "\n"
                           + "Supt Tables ? :   " + cap.Tables + "\n"
                           + "Supt Cookies ?:   " + cap.Cookies + "\n"
                           + "Supt VBs ?    :   " + cap.VBScript + "\n"
                           //+ "Supt Js ?     :   " + cap.JavaScript + "\n"
                           + "Supt AX Ctrls?:   " + cap.ActiveXControls + "\n"
                           + "ScreenHeight  :   " + cap.ScreenPixelsHeight.ToString() + "\n"
                           + "Screen Width  :   " + cap.ScreenPixelsWidth.ToString() + "\n"
                           + "DeviceManufacturer :" + cap.MobileDeviceManufacturer + "\n"
                           + "DeviceModel   :   " + cap.MobileDeviceModel + "\n"
                           + "IP Address    :   " + ip + "\n";
    
    
               Label2.Text = def;
    }


    when i access it on my device i am getting the output like(using Internet Explorer):

    User Agent :PPC; 240x320; HTC_P3450/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.6) Browser Type : Mozilla MajorVersion : 4 MinorVersion : 0 Platform : WinCE Browser : Mozilla Version : 4.0 IsBeta ? : False Is Crawler ? : False Is AOL ? : False Is Win16 ? : False Is Win32 ? : False Supt Frames ? : False Supt Tables ? : False Supt Cookies ?: False Supt VBs ? : False Supt AX Ctrls?: False ScreenHeight : 320 Screen Width : 240 DeviceManufacturer :Unknown DeviceModel : Unknown IP Address : xx.xx.xx.xx

    but when i try to access it dfrom my emulator, out put is (using Internet Explorer):

    User Agent :Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 6.12) Browser Type : Mozilla MajorVersion : 6 MinorVersion : 0 Platform : WinCE Browser : WinCE Version : 6.0 IsBeta ? : False Is Crawler ? : False Is AOL ? : False Is Win16 ? : False Is Win32 ? : False Supt Frames ? : True Supt Tables ? : True Supt Cookies ?: True Supt VBs ? : False Supt AX Ctrls?: True ScreenHeight : 72 Screen Width : 96 DeviceManufacturer :Unknown DeviceModel : Unknown IP Address : xx.xx.xx.xx

     

    Opera and Mozilla's Browser goves me correct details.

    one more thing i would like to know is that: how can i debug mobile web application in VS 2005 Environment, do u guys have any link or any tutorials available for that... 

     

     

     

     

     

     

    Friday, November 7, 2008 3:00 AM

Answers

All replies

  • User1634317999 posted

    Hello,

    the user agents of the images which you use in Microsoft Devivice Emulator are different from those of real devices like your HTC.

    For debugging you can try to attach the debugger to the emulator process with "Attach to process" on the Debug menu.

    Friday, November 7, 2008 7:02 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 7, 2008 7:02 AM
  • User-861818263 posted

     http://www.codeproject.com/KB/mobile/All-about-a-mobile-websit.aspx

     http://worldofasp.net/tut/XHTM_L-MP/Basics_of_XHTML-MP_178.aspx

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 8, 2008 4:28 AM
  • User-654561728 posted
    You can use a web service like handsetdetection.com to automate the process for you and keep the handsets updated.
    Sunday, November 16, 2008 6:52 PM
  • User981004358 posted

    You can also use 51degrees.mobi Foundation API which detects all mobile devices. It is a .NET open source available here http://51degrees.codeplex.com/releases.

    It easily detects if the request is coming from any mobile device and redirects user to mobile landing page. It has user friendly samples to try this out.

     

    Thanks

    Amaresh

    Monday, August 9, 2010 1:32 AM