Determine if the client is a mobile phone or PC

Source: Internet
Author: User

<summary>
Determine if the client is a mobile phone or PC
</summary>
<returns></returns>
public static bool IsMobileDevice ()
{
HttpContext context = HttpContext.Current;

C # Self-band method to determine if it is mobile
if (context. Request.Browser.IsMobileDevice)
{
return true;
}
C # Self-band method to determine if it is mobile
if (context. request.servervariables["Http_x_wap_profile"]! = NULL)
{
return true;
}
C # Self-band method to determine whether the mobile WAP network
if (context. request.servervariables["Http_accept"]! = NULL &&
Context. request.servervariables["Http_accept"]. ToLower (). Contains ("WAP"))
{
return true;
}

Get the client UA comparison merchant number found is
if (context. request.servervariables["Http_user_agent"]! = NULL)
{
Create a list of all mobile types
string[] Mobiles =
New[]
{
"MIDP", "j2me", "avant", "DoCoMo",
"Novarra", "PalmOS", "PalmSource",
"240x320", "OPWV", "cHTML",
"PDA", "Windows CE", "mmp/",
"BlackBerry", "mib/", "Symbian",
"Wireless", "Nokia", "Hand", "Mobi",
"Phone", "CDM", "up.b", "audio",
"sie-", "sec-", "Samsung", "HTC",
"Mot-", "Mitsu", "Sagem", "Sony"
, "Alcatel", "LG", "Eric", "VX",
"NEC", "Philips", "MMM", "XX",
"Panasonic", "Sharp", "WAP", "Sch",
"Rover", "pocket", "BenQ", "Java",
"PT", "PG", "Vox", "Amoi",
"Bird", "Compal", "kg", "Voda",
"Sany", "KDD", "DBT", "Sendo",
"SGH", "Gradi", "JB", "Dddi",
"Moto", "iphone", "Nokia",///Nokia, have a cottage also written this, is always a cell phone, mozilla/5.0 (Nokia5800 XpressMusic) UC AppleWebKit (like Gecko) Safari /530
"MIDP-2",//j2me2.0,mozilla/5.0 (symbianos/9.3; U series60/3.2 nokiae75-1/110.48.125 profile/midp-2.1 configuration/cldc-1.1) applewebkit/413 (KHTML like Gecko) Safari/ 413
"CLDC1.1",//m600/midp2.0/cldc1.1/screen-240x320
"SymbianOS",//Saipan system,
"MAUI",//MTK Cottage default UA
"untrusted/1.0",//suspected copycat UA, basically can be determined or mobile
"Windows CE",//windows ce,mozilla/4.0 (compatible; MSIE 6.0; Windows CE; Iemobile 7.11)
"ipad",//ipad's ua,mozilla/5.0 (ipad; U CPU os 3_2 like Mac os X; ZH-CN) applewebkit/531.21.10 (khtml like Gecko) version/4.0.4 mobile/7b367 safari/531.21.10
"Android",//android also turn WAP? mozilla/5.0 (Linux; U Android 2.1-update1; ZH-CN; XT800 build/tita_m2_16.22.7) applewebkit/530.17 (khtml like Gecko) version/4.0 Mobile safari/530.17
"UCWEB",//ucweb is only to WAP page? Nokia5800 xpressmusic/ucweb7.5.0.66/50/999
"UCWeb",//lowercase ucweb Seemingly is the UC Proxy server mozilla/6.0 (compatible; MSIE 6.0;) Opera Ucweb-squid
"BREW",//Very strange UA, for example: rew-applet/0x20068888 (brew/3.1.5.20; deviceid:40105; LANG:ZHCN) Ucweb-squid
"Yulong",//Yulong phone, yulong-coolpadn68/10.14 ipanel/2.0 ctc/1.0
"Yulong",//or Yulong
"Coolpad",//Yulong cool pie yl-coolpads100/08.10.s100 polaris/2.9 ctc/1.0
"Tianyu",//Tian-language mobile phone tianyu-ktouch/v209/midp2.0/cldc1.1/screen-240x320
"ty-",//Tian-language, ty-f6229/701116_6215_v0230 jupitor/2.2 ctc/1.0
"K-touch",//or heavenly language k-touch_n2200_cmcc/tbg110022_1223_v0801 mtk/6223 release/30.07.2008 browser/wap2.0
"Haier",//Haier mobile phone, haier-hg-m217_cmcc/3.0 release/12.1.2007 browser/wap2.0
"Dopod",//Dopod Mobile
"Lenovo",//Lenovo Mobile, lenovo-p650wg/s100 lmp/lml release/2010.02.22 profile/midp2.0 configuration/cldc1.1
"Lenovo",//Lenovo Mobile, such as: lenovo-p780/176a
"Huaqin",//Hua Qin mobile phone
"aigo-",//Patriot actually also out of cell phone, aigo-800c/2.04 tmss-browser/1.0.0 ctc/1.0
"ctc/1.0",//meaning unknown
"ctc/2.0",//meaning unknown
"CMCC",//Mobile custom mobile phone, k-touch_n2200_cmcc/tbg110022_1223_v0801 mtk/6223 release/30.07.2008 browser/wap2.0
"Daxian",//Large display phone Daxian X180 up. browser/6.2.3.2 (GUI) mmp/2.0
"mot-",//Motorola, mot-motorokre6/1.0 linuxos/2.4.20 release/8.4.2006 browser/opera8.00 profile/midp2.0 Configuration/ CLDC1.1 software/r533_g_11.10.54r
"SonyEricsson",//Sony Ericsson mobile phone, sonyericssonp990i/r100 mozilla/4.0 (compatible; MSIE 6.0; Symbian OS; 405) Opera 8.65 [ZH-CN]
"Gionee",//Jin Li Mobile
"HTC",//HTC phone
"ZTE",//ZTE Mobile, zte-a211/p109a2v1.0.0/wap2.0 profile
"Huawei", or/
"WebOS",//palm cell phone, mozilla/5.0 (webos/1.4.5; U ZH-CN) applewebkit/532.2 (khtml like Gecko) version/1.0 safari/532.2 pre/1.0
"Gobrowser",//3g gobrowser.user-agent=nokia5230/gobrowser/2.0.290 Safari
"Iemobile",//windows ce phone comes with a browser,
"WAP2.0"//WAP 2.0-enabled
};

Loop matching
foreach (string s in mobiles)
{
if (context. request.servervariables["Http_user_agent"].
ToLower (). Contains (S.tolower ()))
{
return true;
}
}
}

return false;
}

Determine if the client is a mobile phone or PC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.