獲取平臺資訊
阿新 • • 發佈:2018-11-03
public static bool CheckAgent() { bool flag = false; string agent = System.Web.HttpContext.Current.Request.UserAgent; string[] keywords = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" }; //排除Window 桌面系統 和 蘋果桌面系統 if (!agent.Contains("Windows NT") && !agent.Contains("Macintosh")) { foreach (string item in keywords) { if (agent.Contains(item)) { flag = true; break; } } } return flag; } /// <summary> /// 判斷系統 /// </summary> /// <returns></returns> public static int CheckAgents() { int ret =0; string agent = System.Web.HttpContext.Current.Request.UserAgent; string[] keywords = {"iPhone", "iPod", "iPad" }; if (agent.Contains("Windows NT")) { ret = 10 ; //Windose } if (agent.Contains("Macintosh")) { ret = 20;// "MacOs"; } if (agent.Contains("Android")) { ret = 30; //"安卓"; } foreach (string item in keywords) { if (agent.Contains(item)) { ret = 40; //"IOS"; break; } } if (agent.Contains("Windows Phone")) { ret = 50;//"WP"; } return ret; } /// <summary> /// 判斷瀏覽器 /// </summary> /// <returns></returns> public static string AgentBrowser() { string Browswr = ""; string agent = System.Web.HttpContext.Current.Request.UserAgent; if (agent.Contains("QQBrowser")) { Browswr = "QQ瀏覽器"; } if (agent.Contains("Chrome")) { Browswr = "谷歌瀏覽器"; } if (agent.Contains("Firefox")) { Browswr = "火狐瀏覽器"; } if (agent.Contains("UCBrowse")) { Browswr = "UC瀏覽器"; } return Browswr; }