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. 

Advertisements
This entry was posted in ASP.NET. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s