views:

274

answers:

5

I have an existing web site and I would like to create a mobile version of it that is more suitable. For instance, the main site uses drop-down menus and we all know those are quite the fail on mobile devices.

I would like to redirect to my mobile version (it will be a subdomain of the current site) if I detect a request from a mobile browser. So when they Google something and come to my site, they will automatically see the mobile version (just like Wikipedia).

Does ASP.NET provide an easy way of doing this? If not, how can I do it?

+1  A: 

There's an article on CodeProject which provides such function.

Darin Dimitrov
Well, this is not exactly the answer I was hoping for. User agent string parsing is a sad last resort for me.
Josh Stodola
That's the only thing that could distinguish a mobile browser request from a normal browser.
Darin Dimitrov
Well, I have a dream! That one day, my four little children will be able to write `If Request.IsMobile`
Josh Stodola
you can... Request.Browser.IsMobileDevice! But you NEED good browser definitions. See my answer (above ;))
BritishDeveloper
+3  A: 

There is a project on codeplex that you can use : Mobile Device Browser File

Project Description

The Mobile Browser Definition File contains definitions for individual mobile devices and browsers. At run time, ASP.NET uses the information in the request header to determine what type of device/browser has made the request.

This project provides a data file that when used with ASP.NET will detect the incoming mobile device and present you as the web developer with a set of 67 capabilities or properties describing the requesting device. These capabilities range from screen size to cookie support and provide all the information you need to adaptively render content for mobile phones and devices.

What is the Mobile Device Browser Definition File?

The Mobile Device Browser Definition File contains capability definitions for individual mobile devices and browsers. At run time, ASP.NET uses this .browser file, along with the information in the HTTP request header, to determine what type of device/browser has made the request and what the capabilities of that device are. This information is exposed to the developer through the Request.Browser property and allows them to tailor the presentation of their web page to suit the capabilities of the target device.

Olivier PAYEN
+3  A: 

You can use the IsMobileDevice property somewhere in the Request.Browser. You need some decent browser definitions though. I use these excellent set of browser definitions: Ocean's place browser definitions.

They are really in depth and the best I've seen. I think he is currently working on .NET4 ones too.

BritishDeveloper
+2  A: 

I think the best solution is WURFL. It is more up date device description repository and it is free. The only inconvenience is .net api is GPL.

fravelgue
+1  A: 

Hello

Use http://51degrees.codeplex.com it is a free ASP.NET mobile api

It has add-in for .NET web sites that'll automatically determine if a mobile device is accessing the site and redirect it to mobile specific content. You do not have to update any of your existing asp.net pages for same.

For more details have a look at http://51degrees.mobi/Forum/tabid/92/forumid/3/postid/114/scope/posts/Default.aspx#114

Amit Patel