asp.net使用用户代理字符串检测任何平板电脑设备

时间:2021-07-07 01:38:44

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

是否可以通过服务器端代码检测来自平板电脑设备(iPad,Android等)的请求?

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

编辑:我需要知道它是Android平板电脑而不是Android手机。

1 个解决方案

#1


4  

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

从检测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); 
        }       
    }

#1


4  

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

从检测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); 
        }       
    }