///<summary> /// 根据 Agent 判断是否是智能手机 ///</summary> ///<returns></returns> public static bool IsMobileDevice() { bool flag = false; string agent = HttpContext.Current.Request.UserAgent; //_log.Debug(string.Format("判断是否是智能手机,UserAgent:{0}", agent)); string[] keywords = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser", "IUC", "UCWEB", "JUC" }; //排除 Windows 桌面系统 if (!agent.Contains("Windows NT") || (agent.Contains("Windows NT") && agent.Contains("compatible; MSIE 9.0;"))) { //排除 苹果桌面系统 if (!agent.Contains("Windows NT") && !agent.Contains("Macintosh")) { foreach (string item in keywords) { if (agent.Contains(item)) { flag = true; break; } } } } return flag; }
Request.Browser.IsMobileDevice
這兩個都可以判斷是手機登錄還是PC登陸,可以參考