Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect iPad with ASP.net

I want to detect if a mobile device is an Tablet (iPad) or not in ASP.net I had a look at 51degrees project but the function to detect a tablet isn't available in the free version - and since we distribute our ASP.net solution to 100's of customers, we cannot buy a 51degrees license for all of them.

Are there any free or open source alternatives for 51degrees available? Or will newer versions of MVC (4?) provide more information in detail than the plain IsMobileDevice()?

Thanks, Konrad

like image 936
Konrad Avatar asked Jul 05 '12 13:07

Konrad


2 Answers

You can request the user agent and check to see if it contains 'ipad' like so

bool isIpad = Request.UserAgent.ToLower().Contains("ipad");
like image 90
Danny Brady Avatar answered Sep 23 '22 15:09

Danny Brady


You don't need to "detect an iPad". Just use Media Queries to give you support for the iPad as the Safari browser that comes with iPad already understands CSS3:

CSS3 Media Queries

/* iPads (landscape) */
@media screen and (min-device-width : 768px) 
    and (max-device-width : 1024px) and (orientation : landscape) {
   ...
}
/* iPads (portrait) */
@media screen and (min-device-width : 768px) and (max-device-width : 1024px) 
    and (orientation : portrait) {
   ...
}

Your best bet is to use HTML5Boilerplate as it fixes some other things for iPad also. Use Modernizr for feature detection; it comes with HTML5Boilerplate.

HTML5 Boilerplate

20 Snippets You should be using from Html5 Boilerplate

like image 44
IrishChieftain Avatar answered Sep 22 '22 15:09

IrishChieftain