How does IsMobileDevice work?

MSDN makes it sound so easy to detect a mobile browser:

if (Request.Browser["IsMobileDevice"] == "true" ) 
{
    Response.Redirect("MobileDefault.aspx");
}

Actually, it looks like you can also just check Request.Browser.IsMobileDevice. But how does this actually work? I don’t even have a .browser file… what’s going on behind the scenes here? Are there some built-in defaults for ASP.NET 2.0?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

A number of *.browser files are shipped with .NET:

C:WindowsMicrosoft.NETFrameworkv2.0.50727CONFIGBrowsers

The runtime uses regular expressions from the *.browser files to match against the incoming User-Agent string, and then sets a bunch of properties based on each match it finds (there can be several in the hierarchy).

If you need in-depth mobile device support, consider installing the MDBF, which adds support for about 400 devices:

http://mdbf.codeplex.com/

Method 2

Now, after 4 years, it’s even more simple

Request.Browser.IsMobileDevice

Method 3

Since for most sites, it is actually the size of the screen that matters and not so much the capabilities (at least when talking about modern phones with things like Safari and Chrome on them) wouldn’t checking the resolution make the most sense?

Request.Browser.ScreenPixelsHeight

and
Request.Browser.ScreenPixelsWidth

Method 4

I wouldn’t rely on the MSDN link, there is no common standard unfortunately for mobile browsers and many try to mimic their non-mobile counterparts. Also it will return true if it doesn’t recognize. See this link.

Method 5

My current understanding is that there’s just one exact solution to the problem of detecting whether a browser is mobile and next detecting its real capabilities. This solution is ScientiaMobile’s WURFL (http://www.scientiamobile.com). Which, as of Aug30, is no longer free for every use. WURFL is now released with an ASP.NET API under AGPL. The data repository also comes with a specific license that disallows both copying and using with APIs different from the standard one (unless one purchases a commercial license).

So for practical purposes other approaches such as 51Degrees cannot be used with more recent and future versions of the WURFL repository and this will make it difficult for 51Degrees to detect new devices (Windows Phone 7.5, for example).

As for MDBF (a dismissed project), it may still work to detect whether a device is mobile (much better than the IsMobileDevice in ASP.NET). It is not entirely reliable as far as properties of the device are concerned. It insists that my HTC Desire Android has a 240×320 screen size, which is patently incorrect.

My company bought a WURFL license and we’re absolutely OK with that.

Method 6

Issues has been resolved while I added 51Degrees, just add 51degrees using Nuget thats all. See more here https://51degrees.codeplex.com

Method 7

Simply use below code,

if (Request.Browser.IsMobileDevice) 
{
    Response.Redirect("MobileDefault.aspx");
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x