aspnet 判斷使用者是訪問手機還是訪問電腦

來源:互聯網
上載者:User

檢測瀏覽器
http://www.enhanceie.com/ua.aspx

判斷依據

http://www.360doc.com/content/12/0715/16/1073512_224357205.shtml

protected void Page_Load(object sender, EventArgs e)
        {
            string agent = Request.Headers["User-Agent"];
            if (string.IsNullOrEmpty(agent))
            {
                return;
            }
            if (ChooseNet(agent))
            {
                Response.Redirect("http://m.4inlook.cn",true);
            }           
        }
        /// <summary>
        /// 對使用者訪問進行判斷 如果是手機的話返回true,否則返回false
        /// </summary>
        /// <param name="userAgent">userAgent可能需要根據檢測的條件不同和更新,適當修改判斷參數</param>
        /// <returns></returns>
        public bool ChooseNet(String userAgent)
        {
            if (userAgent.IndexOf("Noki") > -1 || // Nokia phones and emulators    
                     userAgent.IndexOf("Eric") > -1 || // Ericsson WAP phones and emulators    
                     userAgent.IndexOf("WapI") > -1 || // Ericsson WapIDE 2.0    
                     userAgent.IndexOf("MC21") > -1 || // Ericsson MC218    
                     userAgent.IndexOf("AUR") > -1 || // Ericsson R320    
                     userAgent.IndexOf("R380") > -1 || // Ericsson R380    
                     userAgent.IndexOf("UP.B") > -1 || // UP.Browser    
                     userAgent.IndexOf("WinW") > -1 || // WinWAP browser    
                     userAgent.IndexOf("UPG1") > -1 || // UP.SDK 4.0    
                     userAgent.IndexOf("upsi") > -1 || //another kind of UP.Browser    
                     userAgent.IndexOf("QWAP") > -1 || // unknown QWAPPER browser    
                     userAgent.IndexOf("Jigs") > -1 || // unknown JigSaw browser    
                     userAgent.IndexOf("Java") > -1 || // unknown Java based browser    
                     userAgent.IndexOf("Alca") > -1 || // unknown Alcatel-BE3 browser (UP based)    
                     userAgent.IndexOf("MITS") > -1 || // unknown Mitsubishi browser    
                     userAgent.IndexOf("MOT-") > -1 || // unknown browser (UP based)    
                     userAgent.IndexOf("My S") > -1 ||//  unknown Ericsson devkit browser     
                     userAgent.IndexOf("WAPJ") > -1 ||//Virtual WAPJAG
www.wapjag.de    
                     userAgent.IndexOf("fetc") > -1 ||//fetchpage.cgi Perl script fromwww.wapcab.de    

                     userAgent.IndexOf("ALAV") > -1 || //yet another unknown UP based browser    
                     userAgent.IndexOf("Wapa") > -1 || //another unknown browser (Web based "Wapalyzer")   
                     userAgent.IndexOf("UCWEB") > -1 || //another unknown browser (Web based "Wapalyzer")   
                     userAgent.IndexOf("BlackBerry") > -1 || //another unknown browser (Web based "Wapalyzer")                    
                     userAgent.IndexOf("J2ME") > -1 || //another unknown browser (Web based "Wapalyzer")             
                     userAgent.IndexOf("Opera Mobi") > -1 ||
                     userAgent.IndexOf("Android") > -1 ||
                userAgent.IndexOf("mozilla") > -1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

原文出處:http://www.18sucai.com/article/330.htm

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.