Domanda

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

È stato utile?

Soluzione 3

We now user the old Mobile Device Browser File: http://mdbf.codeplex.com/

And extend it with our own browser file as it was described in this solution: http://www.hanselman.com/blog/MixMobileWebSitesWithASPNETMVCAndTheMobileBrowserDefinitionFile.aspx

Now we can even define own parameters to detect, e.g., the compatibility mode of the internet explorer or define an iPad as a non-mobile device.

Altri suggerimenti

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

bool isIpad = Request.UserAgent.ToLower().Contains("ipad");

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

Here is a total solution for you. This is a site that was built to showcase responsive design using ASP.NET MVC; there is an article, tutorial and complete project download with source code.

http://edcharbeneau.github.com/FoundationSinglePageRWD/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top