Click here to Skip to main content
15,880,503 members
Articles / Web Development / ASP.NET

Mobile Device Browser File

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
8 Jul 2010Ms-PL2 min read 11.3K   1   1
Mobile Device Browser File

We are using the Mobile Device Browser File from CodePlex on our SharePoint publishing portal to detect mobile devices in combination with a simple HTTP Module to redirect them to our mobile site. This works well and as long as we are diligent with getting the latest version of the MDBF, we should be on top of new devices/browsers.

The MDBF currently defines over 60 distinct capabilities of about 400 different devices. Of those capabilities, we are really only interested in the isMobileDevice value. However, many of the other capabilities directly affect the behavior of ASP.NET when a particular browser is detected. The preferredRenderingMime capability tells ASP.NET what content type should be sent as a response header. So in the case of a browser that prefers XHTML, and is not a mobile device and therefore not redirected, ASP.NET obliges by setting the response content type.

Unfortunately the markup coming from our SharePoint portal does not meet the standards of XHTML and causes those browsers to break. We noticed this when we added web slices to the portal and saw that the Windows-RSS-Platform User-Agent was being sent the Content-Type: application/xhtml+xml header. To fix the issue, we added a new browser entry that matched the Windows-RSS-Platform user agent and set the preferredRenderingMime to text/html and at the same time defined some other user agents that we expected to have the same problem. Unfortunately this approach makes being diligent with keeping the latest file from the MDBF team more difficult. With so many devices, we may easily miss some that prefer the XHTML markup but are not mobile devices.

To solve the problem, I created a very simple (4 lines) HttpModule that handles the HttpApplication.PostRequestHandlerExecute event and in the case of Response.ContentType==”application/xhtml+xml” sets the ContentType to “text/html”. This will make it much easier to maintain the MDBF and take care of any other unknown agents.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMobile Detection Pin
Amimpat15-Nov-10 15:16
Amimpat15-Nov-10 15:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.