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?

8 Answers 8

5

You could check their User-Agent string.

Sign up to request clarification or add additional context in comments.

1 Comment

will a user-agent be populated have those specific 'Device Information' as requested in the question ?
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.

1 Comment

MDBF is now very old. For example; it does not contain tablets, or 4G/LTE devices. You could try 51Degrees.mobi from NuGet (nuget.org/packages?q=51degrees). It's a one click install with zero configuration.
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.

Comments

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); } } } 

Comments

1

Please, check this out. Worked fine for me!

http://detectmobilebrowsers.com/

1 Comment

A litte bit more information would have been nice.
0

You need to check for User Agent.

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

Comments

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

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.