A question that repeatedly comes up is how to detect when your website is being accessed by a Windows Phone device. In most cases this discussion ends up with some form of browser detection via the User Agent string. A quick Google/Bing will reveal a number of articles on this topic. In the past I’ve simply referenced Mads Kristensen’s post, Windows Phone 7 user agent. In this post he indicates that the user agent string should look similar to
Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0) Asus;Galaxy6
This is consistent with what the document Designing Web Sites for Phone Browsersstates in the discussion around server side browser detection. Here the user agent string example they give is
Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0) <DeviceManufacturer>;<DeviceModel>
Unfortunately yesterday I was testing a new service I was building (more on that in the coming weeks) that uses the User Agent string. My initial testing with the emulator worked correctly. However, when I got to testing with my LG Optimus 7 device the service was failing because it couldn’t detect that the device was a Windows Phone 7 device. Turns out that the device is sending through a totally bogus User Agent string
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; XBLWP7; ZuneWP7)
My initial reaction is that this sucks! In fact, after further review, it still sucks! How can a device claiming to be a Windows Phone 7 device (and having gone through the Microsoft certification process) emit such rubbish in the User Agent string. The platform is Windows NT 6.1….. really??
Update: Here’s another list of user agent strings that at the time of writing is missing this one – http://www.elucidsoft.com/blog/2010/11/19/windows-phone-7-user-agents/
Update: Someone quite rightly pointed out that this user agent was a result of using the desktop browsing option in IE on the device. Flipping back to mobile browsing restores the correct user agent string as per the above posts. Upshot: you still need to be aware of the different user agent strings that may be sent by a Windows Phone device.