1

If a web application, how can you figure out the visitor is viewing from a mobile phone?

is it also possible figure out the make/model like blackberry versus iphone?

mrblah
  • 99,669
  • 140
  • 310
  • 420

8 Answers8

5

You could check their User-Agent string.

Forgotten Semicolon
  • 13,909
  • 2
  • 51
  • 61
4

Scott Hanselman did a podcast on a module device database that Microsoft made available on Codeplex. It's a .browser file that you put in your ASP.NET (version 2.0+) website, which then helps the framework define the Request.Browser property more closely. You should be able to get a lot of the information that you need from there.

However, that project is no longer supported, and when you're dealing with user agent detection, having an up-to-date resource is very important. You should probably use a similar project, such as 51degrees.mobi or WURFL.

Even without that, at the least you can check Request.Browser.IsMobileDevice.

bdukes
  • 152,002
  • 23
  • 148
  • 175
  • 1
    MDBF is now very old. For example; it does not contain tablets, or 4G/LTE devices. You could try 51Degrees.mobi from NuGet (http://nuget.org/packages?q=51degrees). It's a one click install with zero configuration. – James Rosewell Feb 22 '12 at 10:10
1

Use httpRequest.Browser.IsMobileDevice in Session_Start

void Session_Start(object sender, EventArgs e)
{
    // Redirect mobile users to the mobile home page
    HttpRequest httpRequest = HttpContext.Current.Request;
    if (httpRequest.Browser.IsMobileDevice)
    {
        string path = httpRequest.Url.PathAndQuery;
        bool isOnMobilePage = path.StartsWith("/Mobile/", 
                               StringComparison.OrdinalIgnoreCase);
        if (!isOnMobilePage)
        {
            string redirectTo = "~/Mobile/";

            HttpContext.Current.Response.Redirect(redirectTo);
        }
    }
}
AminM
  • 1,658
  • 4
  • 32
  • 48
1

Please, check this out. Worked fine for me!

http://detectmobilebrowsers.com/

1

You can check the User-Agent string. In JavaScript, that's really easy, it's just a property of the navigator object.

var useragent = navigator.userAgent;

You can check if the device if iPhone or Blackberry in JS with something like

var isIphone = !!agent.match(/iPhone/i),
    isBlackberry = !!agent.match(/blackberry/i);

if isIphone is true you are accessing the site from an Iphone, if isBlackBerry you are accessing the site from a Blackberry.

You can use "UserAgent Switcher" plugin for firefox to test that.

sebarmeli
  • 17,949
  • 7
  • 35
  • 40
0

You need to check for User Agent.

Like... http://www.developershome.com/wap/detection/detection.asp?page=userAgentHeader

Tom
  • 30,090
  • 27
  • 90
  • 124
0

Here is some information from a similar question:

Auto detect mobile browser (via user-agent?)

It involves reading the user-agent header. The answers to that other question include links for scripts for this.

Here is another helpful discussion:

Standard way to detect mobile browsers in a web application based on the http request

Community
  • 1
  • 1
DOK
  • 32,337
  • 7
  • 60
  • 92
0

As preciously stated - user agent

BUT, do you really mean to ask "is it a mobile phone"? Or do you really mean something else?

Lines are blurring these days. I bought a nice little Android slate with 7" screen from eBay for $99. Is that a mobile phone? Is a mini-netbook with 6" screen? Is a Kidnle-like-device?

I'm just wondering why you want to know if it is a mobile 'phone ... screen size? processing power? something else?

You probably did mean mobile 'phone but, if not, please rephrase and we can help further.

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551