Search code examples
c#.netiphoneasp.netipad

How do I check if the useragent is an ipad or iphone?


I'm using a C# asp.net website.

How can I check if the user using ipad or iphone? How can I check the platform?

For example, if the user enter the website from ipad I'd like to display"Hello ipad user"


Solution

  • For iPad user agent is something like:

    Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10

    and for iPhone its somthing like:

    Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3

    Any many more depending on the version and wheather its iPhone 3 or 4

    so better just do a substring search for iPhone and iPad as suggested by another answer