获取客户端的操作系统名称

时间:2011-08-19 06:41:10

标签: c# .net asp.net

我想获得客户端操作系统的名称(即Windows XP,Windows 7,Windows Vista)。

4 个答案:

答案 0 :(得分:5)

使用Request.Browser.Platform,版本位于Request.UserAgent

答案 1 :(得分:4)

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

答案 2 :(得分: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;
        }

答案 3 :(得分: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
         }
相关问题