I have .NET website that is mainly built for desktop browsers but I’m currently making a mobile version of it. What I’m trying to do is load the website according to the device on which it is accessed by the user. Is there a way that I can get information about the user’s device when they request the site?
Regards,
Sumit.
As suggested by others you can use the
System.Web.HttpBrowserCapabilitiesclass accessible throughRequest.Browserhowever without updated browser definition files the information is completely worthless.For example, if you use
Request.Browser.IsMobileDevicethis should give you what you want, but is based on a set of very dated regular expressions in your .NET framework folders in Windows.You can see the kind of problems that can be encountered on a (currently unanswered and unloved) post here on Stack Overflow.
If you do not plan on keeping the browser definition files up to date (which is no small task) then quite simply do not go down this route.
If you simply want to know whether the user is viewing on a mobile device then here are a few options:
Some of those are free, some aren’t and if you are really only interested in whether it is a mobile device, my recommendation would be to use Detect Mobile Browsers.