LOADING

Follow me

Mobile device detection with .NET C#
October 3, 2009|DesignDevelopmentMobile Dev

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 comments
Share

retsoced

6 coments

  • October 6, 2009 at 9:39 pm

    Hey! I’m very glad to see our original code being used to further along mobile device detection. I like it!

    And thanks for the reference!

    Cheers,

    Chris

    • October 7, 2009 at 3:02 am

      I’m happy to give a shou-out to anyone when I use a bit of code that works well for what it was written, no problem.

  • Jeff Howden
    October 24, 2009 at 6:14 pm

    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)

  • October 25, 2009 at 11:38 am

    Thanks Jeff, I will work that into it….

  • November 12, 2009 at 1:10 am

    Hi,
    there is another project called “Apache Mobile Filter”, is a more sphisticated mode to detect mobile devices.

    For more info: http://www.idelfuschini.it/it/apache-mobile-filter-v2x.html

  • Comments are closed.