2011-08-19 87 views

回答

3
HttpBrowserCapabilities browse = Request.Browser; 
string platform = browse.Platform; 
+3

我相信這個結果'WinNT'在XP,Vista和7上不是很有用。 – Bazzz

+1

最好使用下面提到的nuget UAParser。 –

5

使用Request.Browser.Platform,並且版本是Request.UserAgent

+0

@abatishchev Request.UserAgent給了我'Mozilla/5.0(compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)' – masif

+1

@aaa:其實這就是Tejo的答案。 Windows 6.1意味着Windows 7或Windows Server 2008 R2 – abatishchev

+0

感謝您的info..Windows 6.1意味着Windows 7或Windows Server 2008 R2。由@Waqas提供的鏈接幫助我解決了我的問題。 – masif

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 
     } 
2

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

這是如何使用它:

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; 
     }