Recently has been upgrading the company's mobile phone site, out of a touch-screen version of dedicated, after the attempt to determine the corresponding smart phone device through the agent, and then jump to the new mobile site through unremitting efforts, and finally collected a comparison of the entire Smart device agent, and then wrote the program, directly on the code bar, I hope I can help you.
/// <summary>///determine whether a smartphone is based on the agent/// </summary>/// <returns></returns> Public Static BOOLcheckagent () {BOOLFlag =false;stringAgent =HttpContext.Current.Request.UserAgent;string[] keywords = {"Android","IPhone","IPod","IPad","Windows Phone","Mqqbrowser" };//excluding Windows desktop system and Apple desktop systemif(!agent. Contains ("Windows NT") &&!agent. Contains ("Macintosh")){foreach(stringIteminchkeywords) {if(agent. Contains (item)) {Flag=true; Break;}}}returnFlag;}
Code Explanation:
1.!agent. Contains ("Windows NT") &&!agent. Contains ("Macintosh") excludes Windows desktop system and Apple desktop system
2. "Android", "IPhone", "IPod", "IPad", "Windows Phone", "Mqqbrowser" These are the keywords in judging the smart device agent
3. Mqqbrowser for QQ Mobile browser, QQ mobile phone agent is more special, so alone judge
Some of the agents collected below, say to find so many smart devices, it is very easy to:
mozilla/5.0 (IPod; U CPU iPhone os 4_3_2 like Mac os X; ZH-CN) applewebkit/533.17.9 (khtml, like Gecko) version/5.0.2 Mobile/8h7 safari/6533.18.5
mozilla/5.0 (IPhone; U CPU iPhone os 4_3_2 like Mac os X; ZH-CN) applewebkit/533.17.9 (khtml, like Gecko) version/5.0.2 Mobile/8h7 safari/6533.18.5
MQQBROWSER/25 (Linux; U 2.3.3; ZH-CN; HTC Desire S build/gri40;480*800)
mozilla/5.0 (Linux; U Android 2.3.3; ZH-CN; htc_desires_s510e build/gri40) applewebkit/533.1 (khtml, like Gecko) version/4.0 Mobile safari/533.1
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
mozilla/5.0 (IPad; U CPU os 4_3_3 like Mac os X; ZH-CN) applewebkit/533.17.9 (khtml, like Gecko) mobile/8j2
mozilla/5.0 (Windows NT 5.2) applewebkit/534.30 (khtml, like Gecko) chrome/12.0.742.122 safari/534.30
mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) applewebkit/535.1 (khtml, like Gecko) chrome/14.0.835.202 safari/535.1
mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) applewebkit/534.51.22 (khtml, like Gecko) version/5.1.1 safari/534.51.22
mozilla/5.0 (IPhone; CPU iPhone os 5_0 like Mac os X applewebkit/534.46 (khtml, like Gecko) version/5.1 mobile/9a5313e safari/7534.48.3
mozilla/5.0 (IPhone; CPU iPhone os 5_0 like Mac os X applewebkit/534.46 (khtml, like Gecko) version/5.1 mobile/9a5313e safari/7534.48.3
mozilla/5.0 (IPhone; CPU iPhone os 5_0 like Mac os X applewebkit/534.46 (khtml, like Gecko) version/5.1 mobile/9a5313e safari/7534.48.3
mozilla/5.0 (Windows NT 6.1) applewebkit/535.1 (khtml, like Gecko) chrome/14.0.835.202 safari/535.1
Recently has been upgrading the company's mobile site