3

Condition Hi currently I have a function to detect if the client request is from mobile or not. The function is as below.

public bool IsHandheld()
        {
            bool status = false;

            string strUserAgent = Request.UserAgent.ToString().ToLower();
            if (strUserAgent != null)
            {
                if (Request.Browser.IsMobileDevice == true || strUserAgent.Contains("iphone") ||
                    strUserAgent.Contains("blackberry") || strUserAgent.Contains("mobile") ||
                    strUserAgent.Contains("windows ce") || strUserAgent.Contains("opera mini") ||
                    strUserAgent.Contains("palm"))
                {
                    status = true;
                }
            }
            return status;
        }

Problem: This is not enough to detect the handheld device so I got a list of string over internet to compare if it is contained in Userstring

  new string[] { "blackberry" ,"iphone","mobile","windows ce","opera mini",
                    "palm","symbianos", "ipad", "symbianos", "ipod", "blackberry",
                    "sonyericsson", "android", "samsung", "nokia", "wap", "motor"
                });

If the devices went on incresaing then this list would be long

I want to reverse the condition. I want to detect if the request is from PC or laptop not from handheld device. Is there any way to do so? Or am I thinking in the wrong way?

mesimplybj
  • 639
  • 1
  • 5
  • 28
  • possible duplicate of [Auto detect mobile browser (via user-agent?)](http://stackoverflow.com/questions/1005153/auto-detect-mobile-browser-via-user-agent) – Thilo Aug 08 '13 at 10:10
  • @Thilo i want to detect the type of device either PC/Laptop not the browser – mesimplybj Aug 08 '13 at 10:13
  • 1
    I think that's exactly what that other question is about: decide if the browser visiting you is a mobile browser or a desktop browser. – Thilo Aug 08 '13 at 10:15
  • @Thilo Thanks I was misunderstood. Thanks for the link It helped me a lot :) – mesimplybj Aug 08 '13 at 10:31

1 Answers1

2

This is nice Blog i think this will help you.

It recommends using request.Browser.IsMobileDevice

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
manoj
  • 5,235
  • 7
  • 24
  • 45