是否可以通过服务器端代码检测来自平板电脑设备(iPad,Android等)的请求?
编辑:我需要知道它是Android平板电脑而不是Android手机。答案 0 :(得分:4)
来自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);
}
}