|Visual Studio Solution Explorer|
The detection of the user's browser type is encapsulated in a method "IsMobile". The method simply inspects the current controller's Request.UserAgent property for common mobile browser signatures.
If a mobile browser is detected the user is redirected to the mobile area. Instead of just redirecting to the default page of the mobile area I have tried to be clever by maintaining the URL parameters originally specified by the user when redirecting. This means that, for example, if the user is trying to access content at the URL /Home/News?item=1 they will be redirected to /Mobile/Home/News?item=1.
All controller classes and actions marked with the new attribute "MobileRedirectAttribute" will now execute the mobile detection and redirect code each time they are accessed.
An example Visual Studio 2010 solution demonstrating the above code can be downloaded here (11kb).