Mobile device detection with .NET C#

Back in June I wrote about supporting mobile devices with JavasScript and CSS, and at my day job we have been tracking a very significant growth pattern of mobile devices accessing our core domain, so it’s time to take some real action and work towards much better, more streamlined support of these platforms.

I’ve worked with a variety of tool sets recently to accomplish too, on twanonymously.com I integrated PHP mobile device detection to redirect to m.twanonymously.com for a mobile device. What I haven’t finished there yet though, is the design. It’s basically the same thing with some CSS alterations to maintain consistency. But that will come later. At my day job, we are a .NET shop, so I have to find a better solution, one robust enough to handle the 1.2 million daily pageviews we serve up.

The code I am working, started from code I found over here at Web Design Blog, and I have been modifying it to cover a few more devices, specifically ones that are in our top 10. iPod and iPhone are the top two, in that order, followed by T-Mobile Sidekick, and then Android, and after that…. the Sony PSP. Go figure on the PSP. So these are the devices in need of immediate support, and luckily they are all similar in screen dimensions, so no drastic changes for each platform need to be made.

What I’m still working on is trying to figure which devices actually identify themselves as a mobile device when you use IsMobileDevice. So far, iPod, iPhone, BlackBerry do not. My Windows Mobile does though, and I don’t know about the PSP or Android as I have neither. Here’s a link to a test page I have set up so you can see the output. If you feel like testing a device, feel free to post the results in the comments.

Here’s the code I have so far:

[code=’html’]

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>





Mobile Device detection


<;asp:Label ID="DeviceStats" runat="server" />


[/code]

6 thoughts on “Mobile device detection with .NET C#

  1. I tried it with Opera 9.5 on my HTC Pure and it indicated it wasn’t a mobile device. Here’s the exact UA string that the browser is sending:

    HTC-P4600/1.2 Opera/9.5 (Windows NT 5.1; U; en)

Comments are closed.