2009-02-18 83 views
5

我想獲得瀏覽器打開的操作系統版本,實際上我的項目是一個asp.net項目,我想知道哪個操作系統在客戶端上運行,但有一個問題關於它。因爲客戶端將使用XP,但同時將使用Windows CE 5.0,因此Windows CE中的Internet Explorer不如XP中的Internet Explorer,因爲它會將用戶重定向到我設計的頁面Windows CE。那麼有沒有解決方案呢?如何獲得操作系統版本asp.net

謝謝。

+0

閱讀下面的最新解決方案我的答案。 – 2016-08-09 08:17:01

回答

4

它的要點是使用Request.Browser.Platform,版本在Request.UserAgent

0

USER_AGENT參數(在請求參數)應該告訴的故事。

9

使用Request.UserAgent - 這將可能給你所需要的所有信息。

有一個"List of User-Agents"網站提供了大量的示例字符串,但是如果您的客戶端具有有限的設置範圍,那麼值得僅僅嘗試每個字符串並記錄用戶代理作爲初步步驟。

請注意,許多瀏覽器將允許您「欺騙」用戶代理字符串,因此您不能將其用於安全目的 - 但聽起來好像您的用例非常合理。

0
OperatingSystem os = Environment.OSVersion; 
var platform = os.Platform.ToString(); 
var version = os.Version.ToString(); 
var servicePack = os.ServicePack.ToString(); 

您還可以找到與用戶代理的幫助。

String userAgent = Request.UserAgent; 

     if (userAgent.IndexOf("Windows NT 6.3") > 0) 
     { 
      //Windows 8.1 
     } 
     else if (userAgent.IndexOf("Windows NT 6.2") > 0) 
     { 
      //Windows 8 
     } 
     else if (userAgent.IndexOf("Windows NT 6.1") > 0) 
     { 
      //Windows 7 
     } 
     else if (userAgent.IndexOf("Windows NT 6.0") > 0) 
     { 
      //Windows Vista 
     } 
     else if (userAgent.IndexOf("Windows NT 5.2") > 0) 
     { 
      //Windows Server 2003; Windows XP x64 Edition 
     } 
     else if (userAgent.IndexOf("Windows NT 5.1") > 0) 
     { 
      //Windows XP 
     } 
     else if (userAgent.IndexOf("Windows NT 5.01") > 0) 
     { 
      //Windows 2000, Service Pack 1 (SP1) 
     } 
     else if (userAgent.IndexOf("Windows NT 5.0") > 0) 
     { 
      //Windows 2000 
     } 
     else if (userAgent.IndexOf("Windows NT 4.0") > 0) 
     { 
      //Microsoft Windows NT 4.0 
     } 
     else if (userAgent.IndexOf("Win 9x 4.90") > 0) 
     { 
      //Windows Millennium Edition (Windows Me) 
     } 
     else if (userAgent.IndexOf("Windows 98") > 0) 
     { 
      //Windows 98 
     } 
     else if (userAgent.IndexOf("Windows 95") > 0) 
     { 
      //Windows 95 
     } 
     else if (userAgent.IndexOf("Windows CE") > 0) 
     { 
      //Windows CE 
     } 
     else 
     { 
      //Others 
     } 
1

由於所選擇的答案是不是最新的,並提供一個斷開的鏈接,我決定發佈我完成它的方式:

我安裝了一個名爲一個很酷的工具:https://github.com/ua-parser/uap-csharp
用來解析用戶代理到OS,瀏覽器,瀏覽器版本等...

Link to Nuget

這是如何使用它:

public static string GetUserBrowser(string userAgent) 
     { 
      // get a parser with the embedded regex patterns 
      var uaParser = Parser.GetDefault(); 
      ClientInfo c = uaParser.Parse(userAgent); 
      return c.UserAgent.Family; 
     } 


public static string GetUserOS(string userAgent) 
     { 
      // get a parser with the embedded regex patterns 
      var uaParser = Parser.GetDefault(); 
      ClientInfo c = uaParser.Parse(userAgent); 
      return c.OS.Family; 
     }