I am trying to detect device through code but it's not working. However, my device based personalization is working fine. I've enabled device detection in config file already. I can see files under /app_data/devicedetection also. I am using below code to find the device:
var deviceProvider = FiftyOne.Foundation.Mobile.Detection.WebProvider.ActiveProvider;
if (deviceProvider != null)
{
var result = deviceProvider.Match(Request.UserAgent);
vm.IsMobile = result["IsMobile"].ToString().ToLower() == "true";
}
I always get null in deviceProvider variable.
Are there any other approaches that I can follow to detect the device?
var deviceCache = new DeviceDetectionCache(); var device = deviceCache.GetDeviceInformation(Request.UserAgent)