6

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?

Josh Stodola
  • 81,538
  • 47
  • 180
  • 227
  • @fravelgue If you are going to come here and cry about it being a duplicate, then man up and vote to close it and point me to the duplicate. I did not find anything. Your noise is not helpful at all! – Josh Stodola Apr 16 '10 at 19:03
  • sry mate. I think WURFL could be interesting for you. So mdbf has some problems: http://mdbf.codeplex.com/Thread/View.aspx?ThreadId=209583 – fravelgue Apr 16 '10 at 20:27

5 Answers5

3

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
  • 13,219
  • 9
  • 52
  • 62
3

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
  • 2,633
  • 2
  • 24
  • 23
3

Keep it simple...

Heres the JS for the same...

Hope it helps someone..

var useragent = navigator.userAgent;

var isMobile = !!useragent.match(/iPhone|Android|Blackberry|Sony|Nokia|Motorola|Samsung/i),
    isWebBrowser = !!useragent.match(/Mozilla/i);

// Redirect the call accordingly.

  if(isWebBrowser && !isMobile)
            //call to web portal
            alert(" You seem to me... calling from Web Browser")
    else if(isMobile)
        //call to mobile apps
            alert(" Call seems to be from Mobile device...")
    else
    {
        // jus kiddin...
        alert(" Unable to detect the device..... Please report to admin...")
    }
agf
  • 171,228
  • 44
  • 289
  • 238
Gautam
  • 31
  • 1
  • The problem with this solution, which I experienced at least in Chrome, is that the page keeps loading after the mobile browser is detected and you set the location.href to your mobile section. It looks weird for the page to load half-way and the user get forwarded in the middle of it. It would be more smooth if the user was redirected before getting to the web page itself. – John Washam Aug 21 '13 at 18:55
2

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
  • 15,198
  • 7
  • 41
  • 70
1

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

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928