C# 判断是否移动设备。

     /// <summary>
        /// 判断是否移动设备。
        /// </summary>
        /// <returns></returns>
        public static bool IsMobileDevice()
        {
            string[] mobileAgents = { "iphone", "android", "phone", "mobile", "wap", "netfront", "java", "opera mobi", "opera mini", "ucweb", "windows ce", "symbian", "series", "webos", "sony", "blackberry", "dopod", "nokia", "samsung", "palmsource", "xda", "pieplus", "meizu", "midp", "cldc", "motorola", "foma", "docomo", "up.browser", "up.link", "blazer", "helio", "hosin", "huawei", "novarra", "coolpad", "webos", "techfaith", "palmsource", "alcatel", "amoi", "ktouch", "nexian", "ericsson", "philips", "sagem", "wellcom", "bunjalloo", "maui", "smartphone", "iemobile", "spice", "bird", "zte-", "longcos", "pantech", "gionee", "portalmmm", "jig browser", "hiptop", "benq", "haier", "^lct", "320x320", "240x320", "176x220", "w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-", "googlebot-mobile" };

            bool isMoblie = false;

            string userAgent = HttpContext.Current.Request.UserAgent.ToString().ToLower();

            //排除 Windows 桌面系统或苹果桌面系统
            if (!string.IsNullOrEmpty(userAgent) && !userAgent.Contains("macintosh") && (!userAgent.Contains("windows nt") || (userAgent.Contains("windows nt") && userAgent.Contains("compatible; msie 9.0;"))))
            {
                for (int i = 0; i < mobileAgents.Length; i++)
                {
                    if (userAgent.ToLower().IndexOf(mobileAgents[i]) >= 0)
                    {
                        isMoblie = true;
                        break;
                    }
                }
            }

            return isMoblie;
        }

转载标明出处!

时间: 2024-10-12 00:19:15

C# 判断是否移动设备。的相关文章

JS判断是什么设备是什么浏览器-主要用移动页面开发

支持手机上的所有浏览器,下面可在线浏览代码 <!DOCTYPE html><html> <head> <title>JS判断是什么设备是什么浏览器-webkfa.com</title> <meta charset="utf-8"> <meta name="apple-touch-fullscreen" content="YES" /> <meta name=

判断不同IOS设备

var iOSGen = iPhone.generation; if (Debug.isDebugBuild) { Debug.Log("iPhone.generation : " + iPhone.generation); Debug.Log("SystemInfo.deviceType : " + SystemInfo.deviceType); Debug.Log("SystemInfo.deviceModel: " + SystemInfo

navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) 判断是不是 移动设备 &#39;ontouchstart&#39; in window; 判断支不支

navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) 判断是不是 移动设备 'ontouchstart' in window; 判断支不支触屏 navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) 判断是不是 移动设备 'ontouchstart' in window; 判断支不支

is_mobile()判断手机移动设备

is_mobile()判断手机移动设备.md 制作响应式主题时会根据不同的设备推送不同的内容,是基于移动设备网络带宽压力,避免全局接收pc端内容. function is_mobile() { $user_agent = $_SERVER[ 'HTTP_USER_AGENT' ]; $mobile_browser = Array( "mqqbrowser", //手机QQ浏览器 "opera mobi", //手机opera "juc", &qu

判断是不是移动设备

// 判断是不是移动设备var isMobile = { Android: function() { return navigator.userAgent.match(/Android/i) ? true : false; }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i) ? true : false; }, iOS: function() { return navigator.userAgen

判断当前iOS设备的方法

1.在程序中涉及到全屏的宽高的时候,初始化的时候,代码中不要写320和480 #define Screen_height [[UIScreen mainScreen] bounds].size.height #define Screen_width [[UIScreen mainScreen] bounds].size.width  2.使用宏定义方法判断 #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(curren

php判断是不是移动设备

<?php function isMobile() {     // 如果有HTTP_X_WAP_PROFILE则一定是移动设备     if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))     {         return true;     }     // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息     if (isset ($_SERVER['HTTP_VIA']))     {         // 找不到为flase

php判断当前浏览设备是否是手机

今天看到一个php判断是否是手持设备的代码, function isMobile(){ // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){ return true; } // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息 if (isset ($_SERVER['HTTP_VIA'])){ // 找不到为flase,否则为true return stristr($_SERV

Jquery判断是不是移动设备浏览

首先,只判断是否是用移动设备浏览的: // Mobile 这里是只有不再移动设备上访问时,才给相应元素加上 mouseenter  和  mouseleave  事件. if (!navigator.userAgent.match(/mobile/i)) { $('.nav-dots span').mouseenter(function() { $(this).css('background-color', 'rgba(0, 0, 0, 0.2) !important'); }); $('.na