开发者

asp.net detect any tablet device with user agent string

开发者 https://www.devze.com 2023-04-04 00:41 出处:网络
Is it possible 开发者_如何学运维to detect if a request is coming from a tablet device (iPad, Android, etc.) with server side code?

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.


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); 
        }       
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消