How to know if the asp.net site is accessed from a mobile device or from a system/laptop/machine(windows,mac etc)

StackOverflow https://stackoverflow.com/questions/19788159

Question

I have developed a website using asp.net web developer 2010. I would like to redirect to different page if the site is accessed from mobile browser. And, different functionality for windows/mac/linux etc users.

How can I do this?

I referred some posts in some forums, and it is said that I need to depend on third party libraries.

How could I implement this without any third party libraries?

Any one Please help me out.

Any help is appreciated. Thanks!!

Was it helpful?

Solution

The Request.Browser object properties are probably where it is at, these are all options that may be useful to you:

Request.Browser.IsMobileDevice
Request.Browser.MobileDeviceManufacturer
Request.Browser.MobileDeviceModel
Request.Browser.ScreenPixelsWidth
Request.Browser.SupportsXmlHttp

Was there a reason you wanted to avoid a 3rd party component?

We currently use a WURFL device database via 51Degrees.mobi - which works really well.

OTHER TIPS

You can use useragent in asp.net to verify the request are coming from mobile or desktop.

protected override void OnInit(EventArgs e)
        {
            string userAgent = Request.UserAgent;
            if (userAgent.Contains("BlackBerry")
              || (userAgent.Contains("iPhone") || (userAgent.Contains("Android"))))
            {
                //add css ref to header from code behind
                HtmlLink css = new HtmlLink();
                css.Href = ResolveClientUrl("~/mobile.css");
                css.Attributes["rel"] = "stylesheet";
                css.Attributes["type"] = "text/css";
                css.Attributes["media"] = "all";
                Page.Header.Controls.Add(css);
            }
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top