tags:

views:

357

answers:

5

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?

A: 

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.

RandomNoob
+5  A: 

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

C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers

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/

In case it might be helpful, I cover this area in detail in my book: Ultra-Fast ASP.NET.

RickNZ
Excellent. Thank you!
Bryan
A: 

Regarding Mobile Device Browser File:

Quote: "Due to the organizational restructuring of the team that developed and supported the Mobile Device Browser file, we will no longer have the resources to support and update this CodePlex project. The team will be providing two more releases – one on the 27th July 2010 and the final release on the 24th August 2010."

Lucifer
A: 

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
Clever Human
A: 

Please use http://51degrees.codeplex.com/. It is an ASP.NET open source module which detects mobile devices and provides auto redirection to mobile optimized pages when request is coming from mobile device. It makes use of WURFL mobile device database. For redirection there is no need to modify existing ASP.NET web application pages.

Apart from this it also gives upto-date mobile capability information like manufacturer, model, screen height & width, image formats supported and MANY MORE...... which helps to customize pages for best mobile output.

Amit Patel