Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net detect any tablet device with user agent string

Is it possible to detect if a request is coming from a tablet device (iPad, Android, etc.) with server side code?

EDIT: I need to know if it's an android tablet instead of an android phone.

like image 465
Victor Avatar asked Oct 11 '22 01:10

Victor


1 Answers

From Detecting mobile device user agents in ASP.NET (Android):

 //for Mobile device 
    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 66
DaveB Avatar answered Oct 18 '22 00:10

DaveB