主頁 > 知識(shí)庫 > asp.net實(shí)現(xiàn)識(shí)別客戶端瀏覽器或操作系統(tǒng)

asp.net實(shí)現(xiàn)識(shí)別客戶端瀏覽器或操作系統(tǒng)

熱門標(biāo)簽:地圖標(biāo)注專業(yè)團(tuán)隊(duì) 塔城代理外呼系統(tǒng) 濮陽外呼電銷系統(tǒng)怎么樣 天心智能電銷機(jī)器人 地圖標(biāo)注的公司有哪些 代理接電話機(jī)器人如何取消 地圖定位圖標(biāo)標(biāo)注 400電話辦理哪家性價(jià)比高 遂寧市地圖標(biāo)注app

1、通過 UserAgent

protected void Page_Load(object sender, EventArgs e)
  {
    //驗(yàn)證終端
    string agent = Request.Headers["User-Agent"];
    if (choose_net(agent))
    {
      Response.Redirect("/mobile/");
    }
  }

  //驗(yàn)證終端
  public bool choose_net(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 from www.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("Oper") > -1 ||
         userAgent.IndexOf("Android") > -1 ||
      userAgent.IndexOf("mozilla") > -1)
    {
      return true;
    }
    else
    {
      return false;
    }
  }

2.考慮asp.net mvc

里面有for mobile的模版

3.獲取瀏覽器的屬性

復(fù)制代碼 代碼如下:
HttpBrowserCapabilities bc=Request.Browser; Response.Write("script language='javascript'>alert('" + bc.Browser + "');/script>");

 4.js判斷

script type="text/javascript">
    var bro = navigator.userAgent;
    //alert(bro);
    // alert(bro.indexOf("Windows Phone"));
    // iPad 瀏覽器navigator.userAgent(包含iPad)
    if (bro.indexOf("NetFront") > 0 || bro.indexOf("UCWEB") > 0
      || bro.indexOf("iPhone") > 0 || bro.indexOf("Windows CE") > 0
      || bro.indexOf("MIDP-2.0") > 0 || bro.indexOf("Android") > 0
      || bro.indexOf("Opera Mini") > 0 || bro.indexOf("SymbianOS") > 0
      || bro.indexOf("Windows Phone") > 0) {
      window.open("Wap1/Index.aspx", "_top");
    }
    //    else if (bro.indexOf("Windows NT") > 0) {
    //      window.open("NewWeb/default.html", "_top");
    //    }
        else {
          window.open("NewWeb/default.html", "_top");
        }
  /script>

我們再來看下如何獲取PC端的客戶端信息呢

/// summary>
/// 獲取操作系統(tǒng)的名字
/// /summary>
/// param name="userAgent">/param>
/// returns>/returns>
private string GetOSNameByUserAgent(string userAgent)
{
	string osVersion = "未知";
 
	if (userAgent.Contains("NT 10.0"))
	{
		osVersion = "Windows 10";
	}
	else if (userAgent.Contains("NT 6.3"))
	{
		osVersion = "Windows 8.1";
	}
	else if (userAgent.Contains("NT 6.2"))
	{
		osVersion = "Windows 8";
	}
	else if (userAgent.Contains("NT 6.1"))
	{
		osVersion = "Windows 7";
	}
	else if (userAgent.Contains("NT 6.1"))
	{
		osVersion = "Windows 7";
	}
	else if (userAgent.Contains("NT 6.0"))
	{
		osVersion = "Windows Vista/Server 2008";
	}
	else if (userAgent.Contains("NT 5.2"))
	{
		if (userAgent.Contains("64"))
			osVersion = "Windows XP";
		else
			osVersion = "Windows Server 2003";
	}
	else if (userAgent.Contains("NT 5.1"))
	{
		osVersion = "Windows XP";
	}
	else if (userAgent.Contains("NT 5"))
	{
		osVersion = "Windows 2000";
	}
	else if (userAgent.Contains("NT 4"))
	{
		osVersion = "Windows NT4";
	}
	else if (userAgent.Contains("Me"))
	{
		osVersion = "Windows Me";
	}
	else if (userAgent.Contains("98"))
	{
		osVersion = "Windows 98";
	}
	else if (userAgent.Contains("95"))
	{
		osVersion = "Windows 95";
	}
	else if (userAgent.Contains("Mac"))
	{
		osVersion = "Mac";
	}
	else if (userAgent.Contains("Unix"))
	{
		osVersion = "UNIX";
	}
	else if (userAgent.Contains("Linux"))
	{
		osVersion = "Linux";
	}
	else if (userAgent.Contains("SunOS"))
	{
		osVersion = "SunOS";
	}
	else
	{
		osVersion = HttpContext.Current.Request.Browser.Platform;
	}
	return osVersion;
}

基本上很全了,小伙伴們根據(jù)需求自由選擇吧

您可能感興趣的文章:
  • JavaScript 檢測瀏覽器和操作系統(tǒng)的腳本
  • jsp 獲取客戶端的瀏覽器和操作系統(tǒng)信息
  • php中修改瀏覽器的User-Agent來偽裝你的瀏覽器和操作系統(tǒng)
  • JavaScript高級(jí)程序設(shè)計(jì)閱讀筆記(十六) javascript檢測瀏覽器和操作系統(tǒng)-detect.js
  • PHP獲取用戶的瀏覽器與操作系統(tǒng)信息的代碼
  • JS獲得瀏覽器版本和操作系統(tǒng)版本的例子
  • javascript實(shí)現(xiàn)獲取瀏覽器版本、操作系統(tǒng)類型
  • 基于javascript代碼檢測訪問網(wǎng)頁的瀏覽器呈現(xiàn)引擎、平臺(tái)、Windows操作系統(tǒng)、移動(dòng)設(shè)備和游戲系統(tǒng)

標(biāo)簽:吉林 汕頭 河南 重慶 麗江 婁底 本溪 宜春

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net實(shí)現(xiàn)識(shí)別客戶端瀏覽器或操作系統(tǒng)》,本文關(guān)鍵詞  asp.net,實(shí)現(xiàn),識(shí)別,客戶端,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net實(shí)現(xiàn)識(shí)別客戶端瀏覽器或操作系統(tǒng)》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp.net實(shí)現(xiàn)識(shí)別客戶端瀏覽器或操作系統(tǒng)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章