欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

判断是否是手机

程序员文章站 2022-08-09 18:01:43
public static bool CheckAgent() { bool flag = false; string agent = HttpContext.Current.Request.UserAgent; string[] keywords = { "Android", "iPhone", ......

public static bool checkagent()
{
bool flag = false;

string agent = httpcontext.current.request.useragent;
string[] keywords = { "android", "iphone", "ipod", "ipad", "windows phone", "mqqbrowser" };

//排除 windows 桌面系统
if (!agent.contains("windows nt") || (agent.contains("windows nt") && agent.contains("compatible; msie 9.0;")))
{
//排除 苹果桌面系统
if (!agent.contains("windows nt") && !agent.contains("macintosh"))
{
foreach (string item in keywords)
{
if (agent.contains(item))
{
flag = true;
break;
}
}
}
}

return flag;
}