Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net: How to detect iOS/Android?

I've recently launched a web app written in C#/.net 4.0 making extensive use of jQuery & jQuery UI to give the best possible user experience.

However some users have reported problems when using the site through an iPhone or Android devices.

What is the best accepted method of detecting both iOS and Android? so that I can then tweak the UI for each browser.

like image 214
Peter Bridger Avatar asked Jun 01 '11 13:06

Peter Bridger


3 Answers

Generically speaking, you should detect the browser server side, and then render the correct templates/viewport to the browser. Check the user agent string sent to the server, by the browser - iOS generally contains the substring, "iPhone" and Android uses "Android" followed by the version number ("Android 2.2")

like image 54
Andrew Weir Avatar answered Oct 02 '22 18:10

Andrew Weir


I think the best solution is to try the string

Request.ServerVariables["HTTP_USER_AGENT"]

That will return the word android for android devices so far. Windows is easy to detect. Somebody help me with the other fruit.

See more detailed solution at http://www.codeproject.com/Articles/34422/Detecting-a-mobile-browser-in-ASP-NET

like image 33
Sam Patirage Avatar answered Oct 02 '22 19:10

Sam Patirage


Here's an ASP.NET extension that (apparently, I haven't used it) does all that for you :)

http://51degrees.codeplex.com/

like image 28
jvenema Avatar answered Oct 02 '22 20:10

jvenema