Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!!

like image 898
Mahe Avatar asked Nov 05 '13 11:11

Mahe


2 Answers

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.

like image 105
rajbyexample Avatar answered Oct 23 '22 11:10

rajbyexample


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);
            }
        }
like image 25
Kuldeep Avatar answered Oct 23 '22 11:10

Kuldeep