Dashboard > Castle Contrib > ... > Castle.MonoRail.ViewComponents > MobileFilter
MobileFilter
Added by James Curran, last edited by James Curran on Sep 22, 2007  (view change)
Labels: 
(None)


MobileFilter Class

Detects if controller is being accessed via a mobile device.

Remarks

Detects if controller is being accessed via a mobile device. If so, it will change the layout name by prepending "mobile-" to the name, and by defining a PropertyBag value "_IsMobileDevice". This assumes that, for the most part, the layout contain a lot of extreneous elements (fly-out menus, images) as well as the CSS include. By changing the layout (and including a different CSS) the same controller and view template used normal output,  can be reformated to be presentable on a mobile device. This will detect any mobile device that has a *.browser file defined either for the system (in C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers) or locally (in ~\App_Browsers). Since these tend to be out of date, it also triggers on "Windows CE" or "Smartphone" in the user-agent.

 TODO: An explicit test for iPhones should probably be added.

Example

[Layout("default"), Rescue("generalerror")]
 [Filter(ExecuteEnum.BeforeAction,typeof(MobileFilter))]
 public class ShowController : SmartDispatcherController

If viewed from a mobile device, the layout will be changed to "mobile-default".

Site running on a free Atlassian Confluence Community License granted to Castle Project. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators