March 19, 2009

Develop for mobile devices using ASP.NET and free device capability data!

If having to juggle with the quirks of 3 or 4 PC browsers in order for your website to look good on all of them pushes you to inflict physical damage to your keyboard/screen (according to taste), try developing for mobile devices. Scrap everything you knew you could take for granted when developing for the PC, the plethora of mobile devices and browsers on the market vary in just about every aspect - from display size to cookie support and from.mp3 to CSS support.

But before adapting your website's content and appearance to the capabilities of the specific device that made the request, you need an answer to a very obvious question: what are its capabilities?

My team in Microsoft Ireland have recently published on Codeplex a project that aims to answer that question. It offers free device capability data for hundreds of mobile devices, neatly packed in a .browser ASP.NET configuration file (baptised the Mobile Device Browser File). Once deployed in your website (a simple matter of copying the file in a subfolder of the App_Browsers folder) the data will be accessible at runtime using the very simple API exposed by ASP.NET's HttpRequest.Browser, like in the example below:

int bitDepth = int32.Parse(Request.Browser["ScreenBitDepth"]);
if (bitDepth < 16)
{
imageControl.ImageUrl = "logo_4bit.png";
}
else
{
imageControl.ImageUrl = "logo_16bit.png";
}

Of course, you will still need to give a measure of your virtuosity when defining when, how and what to adapt in your website.

No comments: