Take the 2-minute tour ×

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.

share|improve this question
possible duplicate of Detecting Requests from Mobile Browsers in ASP.NET –  jfar Aug 16 '10 at 23:40
@jfar, MVC has specific requirements for this. See the Hanselman post. AFAICS, the answer you link doesn't cover that. –  Craig Stuntz Aug 17 '10 at 22:17
You can see some solutions here: stackoverflow.com/questions/6844020/… –  user898684 Aug 17 '11 at 13:06
add comment

4 Answers

up vote 7 down vote accepted

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.

share|improve this answer
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 Aug 16 '10 at 21:12
add comment

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


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


share|improve this answer
add comment

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.

share|improve this answer
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 Aug 16 '10 at 21:05
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. –  Cat Man Do Aug 16 '10 at 21:15
@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 Aug 16 '10 at 21:24
@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 Aug 16 '10 at 21:26
Don't ever redirect a deep link to a mobile home page, though. That breaks external links and irritates mobile users. –  Craig Stuntz Aug 17 '10 at 12:50
show 2 more comments

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.

share|improve this answer
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 Aug 16 '10 at 21:18
@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 Aug 17 '10 at 8:58
add comment

Your Answer


