Try to obtain the corresponding smartphone device identity through the agent, according to the different identification to output the corresponding device required display style and other.
After efforts, and finally collected a relatively full of intelligent equipment agent, the corresponding judgment process and code as follows, do not understand the message.
public static bool Checkagent ()
{
BOOL flag = FALSE;
String agent = HttpContext.Current.Request.UserAgent;
string[] keywords = {"Android", "IPhone", "IPod", "IPad", "Windows Phone", "Mqqbrowser"};
Troubleshooting Windows Desktop Systems
if (!agent. Contains ("Windows NT") | | (Agent. Contains ("Windows NT") && agent. Contains ("compatible; MSIE 9.0; ")))
{
Exclude Apple Desktop System
if (!agent. Contains ("Windows NT") &&!agent. Contains ("Macintosh"))
{
foreach (String item in keywords)
{
if (agent. Contains (item))
{
Flag = true;
Break
}
}
}
Flag = true;
}
return flag;
}
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 special, so separate judgment (in the current Android system, only the browser support HTML5 language).
C # using UserAgent to Judge Smart devices (ANDROID,IOS,PC,MAC)