views:

77

answers:

5

I've read that its bad (not advised) to use User Agent Sniffing to send down the correct content for a mobile browser, so I'm wondering what IS the best way to do this?

I'm using ASP.NET MVC, and I've built my site and it works well on desktop browsers, so I'm looking to begin building a mobile version. When a mobile browser comes to my site, I'd like to use a different set of Views, which ideally posses the following attributes:

  1. Link to pre-scaled images
  2. Use minimal javascript
  3. Remove all but essential content

My first thought was to sniff the user agent, and then send down a different .CSS file, but as stated above I've read that this is a bad way to do this, so I'm asking you for your thoughts.

+5  A: 

The user agent is really all you have in a HTTP GET request, but you should let someone else maintain the list. We use the Microsoft Mobile Device Browser File with a custom view engine in a manner roughly similar to this Scott Hanselman post.

Craig Stuntz
Thanks, this is what I kinda thought, guess I misunderstood the reason I was told not to. I completely agree that maintaining a compatibility list is a PITA!
Nate Bross
+2  A: 

The best way to detect a mobile browser is to use this wonderful codeplex project:

http://mdbf.codeplex.com/

For background on how you could create targeted views read here:

http://www.hanselman.com/blog/MixMobileWebSitesWithASPNETMVCAndTheMobileBrowserDefinitionFile.aspx

Nissan Fan
A: 

The simplest approach could be use a separate domain "m.yourdomain.com" or "yourdomain.mobi" (Source) that way you can assume that the user is on a mobile device.

ChrisF
In this case, would I use a browser agent and a cookie to redirect once, and if they came back, assume I've mislabeled their user agent and let them continue on full site?
Nate Bross
This approach can be painful. You should assume anyone going to m.website.com wants the mobile site but always give them a link to the full site in the footer.
Nissan Fan
@Nissan - that's a good idea, though the more I think about it the more I'm convinced my answer is not necessarily a good idea.
ChrisF
@Nate - you could do or just have a link to the mobile site on the main site, though I'm not convinced by my answer any more ;)
ChrisF
I meant have the redirect on my www. domain, redirect once to m. domain. I agree, having separate domains is a fairly safe option. I think I'm going to use the mobile browser file, since it seems pretty useful.
Nate Bross
Don't ever redirect a deep link to a mobile home page, though. That breaks external links and irritates mobile users.
Craig Stuntz
@Craig, I agree, thanks.
Nate Bross
A: 

While I believe it's frowned upon to sniff for browser to determine capability and you should use capability sniffing, such as JQuery.support. When it comes to actually presenting significantly different layouts then I think you have to sniff for the browser ID and act accordingly.

Lazarus
That works *after the page is loaded.* When responding to a `GET` request on the server, however, there's no way to do this.
Craig Stuntz
@Craig - Of course, I had my head thinking from client-side but the issue is processing from server-side where you obviously only have the browser ID supplied during the GET.
Lazarus
A: 

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