C#获取终端类型

  #region 获取终端类型
        /// 
        /// 获取终端类型
        /// 
        /// 
        public static BrowserTerminalModel GetBrowserTerminal()
        {
            var u = HttpContext.Current.Request.UserAgent;
            var model = new BrowserTerminalModel();
            model.Trident = u.IndexOf("Trident",StringComparison.CurrentCultureIgnoreCase)!=-1;
            model.Presto =u.IndexOf("Presto",StringComparison.CurrentCultureIgnoreCase)!=-1; //opera内核
            model.WebKit =u.IndexOf("AppleWebKit",StringComparison.CurrentCultureIgnoreCase)!=-1; //苹果、谷歌内核
            model.Gecko = u.IndexOf("Gecko", StringComparison.CurrentCultureIgnoreCase) != -1&& !(u.IndexOf("KHTML", StringComparison.CurrentCultureIgnoreCase) != -1);//火狐内核
            model.Mobile = u.IndexOf("Mobile", StringComparison.CurrentCultureIgnoreCase) != -1;
            model.Ios = u.IndexOf("Mac OS X", StringComparison.CurrentCultureIgnoreCase) != -1;
            model.Android =u.IndexOf("Android", StringComparison.CurrentCultureIgnoreCase) != -1;
            model.IPhone = u.IndexOf("iPhone", StringComparison.CurrentCultureIgnoreCase) != -1;
            model.IPad = u.IndexOf("iPad", StringComparison.CurrentCultureIgnoreCase) != -1;
            model.WebApp = u.IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1;
            return model;
        }
        /// 
        /// 浏览器终端类型
        /// 
        public class BrowserTerminalModel
        {
            #region 实体成员
            /// 
            /// IE内核
            /// 
            public bool Trident { get; set; }
            /// 
            /// opera内核
            /// 
            public bool Presto { get; set; }
            /// 
            /// 苹果、谷歌内核
            /// 
            public bool WebKit { get; set; }
            /// 
            /// 火狐内核
            /// 
            public bool Gecko { get; set; }
            /// 
            /// 是否为移动终端
            /// 
            public bool Mobile { get; set; }
            /// 
            /// ios终端
            /// 
            public bool Ios { get; set; }
            /// 
            /// android终端
            /// 
            public bool Android { get; set; }
            /// 
            /// uc浏览器终端
            /// 
            public bool Linux { get; set; }
            /// 
            /// 是否为iPhone或者QQHD浏览器
            /// 
            public bool IPhone { get; set; }
            /// 
            /// 是否iPad
            /// 
            public bool IPad { get; set; }
            /// 
            /// 是否web应该程序,没有头部与底部
            /// 
            public bool WebApp { get; set; }

            #endregion
        }
        #endregion

你可能感兴趣的:(c#,c#)