Hi,
The problem with Request.Browser.IsMobileDevice is that it will classify a tablet as a mobile device.
If you need to discern between mobile, tablet and desktop. Then use the following extension method.
public static class HttpBrowserCapabilitiesBaseExtensions
{
public static bool IsMobileNotTablet(this HttpBrowserCapabilitiesBase browser)
{
var userAgent = browser.Capabilities[""].ToString();
var r = new Regex("ipad|(android(?!.*mobile))|xoom|sch-i800|playbook|tablet|kindle|nexus|silk", RegexOptions.IgnoreCase);
var isTablet = r.IsMatch(userAgent) && browser.IsMobileDevice;
return !isTablet && browser.IsMobileDevice;
}
}
Then to use it is easy. Just import the namespace and reference the method.
using Web.Public.Helpers; ... if (Request.Browser.IsMobileNotTablet() && !User.IsSubscribed) ....