views:

37

answers:

4

How do i know if my webpage (asp.net) is being loaded from a mobile device? I want to apply mobile.css instead of normal.css. I consider a mobile device all phones, psp/ds/wii, itouch and ipad could go either way.

I dont know if i am choosing the css by headers server side changing the css file or if i should use JS or something. How do i do this?

+1  A: 

Check the UserAgent to see what device is requesting your page, e.g.:

http://www.codeproject.com/KB/aspnet/conquering_browsers.aspx

Google knows more.

Select0r
But it actually doesnt say if its mobile or not.
acidzombie24
Yes, it does: http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones
Select0r
A: 

You could detect it on server side by looking into UserAgent property of the Request object. That should work with most mobile browser but will require writing a couple of "or" statements.

For example to detect an iPhone you can use something like this

if (Request.UserAgent.Contains("iPhone")) {
     // load iphone specific JS/CSS here
}
RaYell
A: 

I think this .net api, 51degrees, is the best for WURFL.

fravelgue
Apparently there's a .net WURFL library in the works, referenced at their site: http://wurfl.sourceforge.net/ on the left menu.
Fanis
A: 

Any library that you might use to detect whether the site is being accessed by a mobile device would ultimately, in most probability pick up the User Agent string and then compare it with a device data store ( like WURFL or .Mobi ).

There are several open source libraries like Tera_WURFL but I am not sure what is available for .Net applications.

One thing that we did in one of the projects that I worked with was instead of checking for all the mobile User Agents and defaulting to desktop if not found, we did the other way around. We check for all the desktop user agents and defaulted to mobile if not found. I feel this improves the performance as there are reduced number of comparisons.

Arup Chowdhary