Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取asp.net操作系统版本_C#_Asp.net_Windows Mobile - Fatal编程技术网

C# 如何获取asp.net操作系统版本

C# 如何获取asp.net操作系统版本,c#,asp.net,windows-mobile,C#,Asp.net,Windows Mobile,我想得到浏览器打开的操作系统版本,实际上我的项目是一个asp.net项目,我想知道哪个操作系统在客户端上运行,但有一个问题。由于客户端将使用xp,但同时将使用Windows CE 5.0,因此Windows CE中的internet explorer不如xp中的,因此我将用户重定向到我为Windows CE设计的页面。那么有什么解决办法吗 谢谢。用户代理参数(在请求参数上)应该说明问题。其要点是使用request.Browser.Platform,版本在request.UserAgent使用-这

我想得到浏览器打开的操作系统版本,实际上我的项目是一个asp.net项目,我想知道哪个操作系统在客户端上运行,但有一个问题。由于客户端将使用xp,但同时将使用Windows CE 5.0,因此Windows CE中的internet explorer不如xp中的,因此我将用户重定向到我为Windows CE设计的页面。那么有什么解决办法吗


谢谢。

用户代理参数(在请求参数上)应该说明问题。

其要点是使用
request.Browser.Platform
,版本在
request.UserAgent

使用-这可能会提供您需要的所有信息

有一个网站提供了大量的示例字符串,但是如果您的客户机的设置范围有限,那么作为一个初步步骤,只需尝试其中的每一个并记录用户代理就值得了


请注意,许多浏览器都会允许您“欺骗”用户代理字符串,因此您不能出于安全目的使用它-但听起来您的用例非常合理。

我使用了它,它工作得很好。我在我的一个应用程序中使用过它

您还可以在用户代理的帮助下找到

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
         }

由于所选答案不是最新的,并且提供了一个断开的链接,我决定发布我完成它的方式:

我安装了一个名为:
的很酷的工具,可以将用户代理解析为操作系统、浏览器、浏览器版本等

这就是它的使用方式:

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

不要只发布简单的链接,否则如果链接断了,你的答案就一文不值了!请阅读下面我的答案,了解最新的解决方案。
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;
        }