has been upgrading the company's mobile site recently, out of a touch-screen version of the special, do a good job, after the agent to determine the corresponding smart phone devices, and then jump to the new mobile site through unremitting efforts, and finally collected a relatively full of smart device agent, and then wrote the program, directly on the code, I hope I can help you.
Copy Code code as follows:
<summary>
To determine whether a smartphone is based on the agent
</summary>
<returns></returns>
public static bool Checkagent ()
{
BOOL flag = FALSE;
String agent = HttpContext.Current.Request.UserAgent;
string[] keywords = {"Android", "IPhone", "IPod", "IPad", "Windows Phone", "Mqqbrowser"};
Excluding window desktop systems and Apple Desktop systems
if (!agent. Contains ("Windows NT") &&!agent. Contains ("Macintosh"))
{
foreach (String item in keywords)
{
if (agent. Contains (item))
{
Flag = true;
Break
}
}
}
return flag;
}
Code Explanation:
1.!agent. Contains ("Windows NT") &&!agent. Contains ("Macintosh") excluding window desktop systems and Apple Desktop systems
2. "Android", "IPhone", "IPod", "IPad", "Windows Phone", "Mqqbrowser" are the key words in the smart device agent.
3. Mqqbrowser for QQ Mobile browser, QQ mobile phone agent is more special, so the individual judge
The following collection of some agents, say to find so many smart devices, not easy AH:
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
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
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
mozilla/5.0 (IPhone; CPU iPhone os 5_0 like Mac os X applewebkit/534.46 (khtml, like Gecko) version/5.1 mobile/9a5313e
mozilla/5.0 (IPhone; CPU iPhone os 5_0 like Mac os X applewebkit/534.46 (khtml, like Gecko) version/5.1 mobile/9a5313e
mozilla/5.0 (Windows NT 6.1) applewebkit/535.1 (khtml, like Gecko) chrome/14.0.835.202 safari/535.1