3

I am trying to find out if a user viewing my site is a mobile user. I have used "HttpContext.Current.Request.Browser.IsMobileDevice " and found it pretty useless as it didn't not pick up on my usage when viewing the site on my phone.

Is there another way to find out if the user is a mobile user that works better?

I have looked at user agent and that just looks messy!

I should point out that this has nothing to do with CSS, I want to log if the user is a mobile user in a database table.

And yes, I know google analytics can do this already but unfortunately its not my decision!

Thanks

1

3 Answers 3

7

Check out

51degrees

It’s provided as a .NET open source class library that detects mobile devices and browsers, enhancing the information available to .NET programmers. Using 51Degrees.mobi Device Data, accurate screen sizes, input methods, plus manufacturer and model information are all available. Mobile handsets can optionally be redirected to content designed for mobile devices. Smart phones, tablets and feature phones are all supported.

As pointed out in the comments.

The detection and redirection part of the product offering is free. The free trial is for their mobile optimzation products

11
  • This is only a free trial - you have to pay $$ to use it. Mar 14, 2012 at 16:29
  • 1
    +1. I have used 51degrees with great success. There is no easy way to look at a user agent string to determine a mobile browser but 51degrees pulls it off. They do this by using a comprehensive database of mobile user agent strings. A word of warning, update frequently. If you don't you could either erroneously determine that a new browser (or update) is mobile when it isn't, or fail to detect that a browser is in fact mobile. If you update frequently you won't have these problems.
    – Devin
    Mar 14, 2012 at 16:33
  • IIRC, 51degrees uses WURFL as it's datasource.
    – rrrr-o
    Mar 14, 2012 at 16:35
  • @IrishChieftain the detection and redirection part of the product offering is free. The free trial is for their mobile optimzation products.
    – Devin
    Mar 14, 2012 at 16:37
  • 1
    I also think it is worth pointing out that 51degrees is an httpmodule and will update the HttpContext.Current.Request.Browser.IsMobileDevice using the WURFL database rather than the built in asp.net detection.
    – Devin
    Mar 14, 2012 at 16:47
6

See my comment on your question for a more thorough answer, but for a simple check to see if the user is a mobile user I would personally suggest

http://detectmobilebrowsers.com/

5

Try to test with this code....

    string sUA = Request.UserAgent.Trim().ToLower();

    uaString.InnerText = Request.UserAgent;

    if (sUA.Contains("ipod") || sUA.Contains("iphone"))
        isMobile = true;

    if (sUA.Contains("android"))
        isMobile = true;

    if (sUA.Contains("opera mobi"))
        isMobile = true;

    if (sUA.Contains("windows phone os") && sUA.Contains("iemobile"))
        isMobile = true;

    if (sUA.Contains("fennec"))
        isMobile = true;
4
  • 1
    Let's just hope nobody uses a Blackberry. Or a Palm device. Terrible, terrible idea.
    – rrrr-o
    Mar 14, 2012 at 16:52
  • 1
    This will not always work. I'd strongly recommend not using a brittle scheme like this. The 51degrees answer (or anything using a more comprehensive database) is a much more complex, yet reliable solution. I have gone down this road before and it was unusable. We got to the point where we had 60 if statements similar to the above and we were still hitting cases where the detection was incorrect. I can tell you from experience you'll be happier if you go with a more complete solution.
    – Devin
    Mar 14, 2012 at 17:15
  • It seems like a more robust approach may be to inspect the resolution of the device and categorize it that way.
    – msigman
    Mar 14, 2012 at 22:13
  • what is uaString.InnerText ?
    – KumarHarsh
    Jun 18, 2020 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.