Using the mobile API

IsMobile

The IsMobile method is used to check whether the current view is to be shown as mobile or not. Mobile detection and view logic will be performed earlier in the page render cycle. 

There a two main properties available for mobile development

WAFContext.Request.IsMobile

This is used to check whether the view should be displayed for mobile. This property is automatically set. There are 4 ways for this property to have the value True.

  • Querystring parameter '?waf_client=mobile' was passed.
  • The switch to mobile link was pressed (will result in the above request)
  • The device used is detected as a mobile.
  • Cookie has been set for mobile (as a result of a prior request. One of the above).  

The property will never be true if mobile support is not enabled in the installation settings. The clear your current mobile settings in your browser delete cookies.   

WAFContext.Request.IsMobileUserAgent

The IsMobile property is set based on logic as described above. In some cases you might not want to have this logic applied. In this case use the IsMobileUserAgent to do check the user agent directly. The isMobile use the same property internally.  

How to override mobile detection

The built in mobile detection code is fairly simple. 

In some cases you might want to override what get detected as a mobile. To do this write a provider class that implements the IMobileDetectionProvider interface.

public class MyCustomMobileDetector : WAF.Presentation.Web.MobileSupport.IMobileDetectionProvider
{
    public bool ClientDetectedAsMobile(HttpRequest request) {
       //Do something with the request here to detect device type 
    }
}

Setting the provider

Go to the installation settings and find your provider in the 'Mobile detection provider' drop down box.

mobile settingsmobile settings