C # using UserAgent to Judge Smart devices (ANDROID,IOS,PC,MAC)

Source: Internet
Author: User

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)

Related Article

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.