How many times did I mention lately I love ASP.NET 2.0 and VB2005? Not enough. Yet one more time – I absolutely love Whidbey!
So, I decided to make vbfeeds.com mobile-enabled so visitors could browse it on their mobile device.
In the past I would have a choice of setting up a virtual directory with mobile-only scripts or parse the browser HTTP_USER_AGENT request header and search for “Windows CE“, “PPC“, “Pocket IE“ and such. I didn't fancy either of the options.
Here is where the new ASP.NET features come in handy - Request.Browser.IsMobileDevice and Master Pages. I basically added the following couple of lines in every ASPX page
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
If Request.Browser.IsMobileDevice Then
MasterPageFile = "~/MasterPageMobile.master"
MasterPageFile = "~/MasterPageFull.master"
The code above assigns master page depending on Request.Browser.IsMobileDevice value. That's it!
Just too darn simple - like many things in VB2005!
Now, if you navigate to any of the vbfeeds.com pages on a mobile device, it will be rendered using a smaller, mobile friendly master page.
The good thing is that I can now screen and approve the new web feed items right from my Pocket PC phone the very same minute they aggregated into the database!
If you don't have a mobile device to try vbfeeds.com on it, there is a QueryString parameter I added that switches vbfeeds.com to the mobile Master Page just like you were to browse the site from a mobile phone. Try it in your desktop browser - just add mobile=true to any page URL, for example, http://vbfeeds.com/?mobile=true or http://vbfeeds.com/post.aspx?id=680&mobile=true