【问题标题】:How to get operating system version asp.net如何获取操作系统版本 asp.net
【发布时间】:2010-10-08 08:56:41
【问题描述】:

我想获取浏览器打开的操作系统版本,实际上我的项目是一个asp.net项目,我想知道客户端上运行的是哪个操作系统,但有一个问题。因为客户端会使用 xp 但同时会使用 Windows CE 5.0,所以 Windows CE 中的 Internet Explorer 不如 xp 中的,因为它我会将用户重定向到我设计的页面视窗 CE。那么有什么解决办法吗?

谢谢你..

【问题讨论】:

  • 阅读下面我的答案以获得最新的解决方案。

标签: c# asp.net windows-mobile


【解决方案1】:

USER_AGENT 参数(在请求参数中)应该能说明问题。

【讨论】:

    【解决方案2】:

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

    我安装了一个很酷的工具,名为:https://github.com/ua-parser/uap-csharp
    ,它将用户代理解析为操作系统、浏览器、浏览器版本等...

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:
        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
                 }
        

        【讨论】:

          【解决方案5】:

          我用过这个,效果很好。我已经在我的一个应用中使用了它。

          http://blogs.microsoft.co.il/blogs/rotemb/archive/2009/01/26/browser-and-operating-system-detection-in-asp-net.aspx

          【讨论】:

          • 不要只发布普通链接,否则如果链接断开,您的答案将毫无价值!
          【解决方案6】:

          使用Request.UserAgent - 这将可能提供您需要的所有信息。

          有一个 "List of User-Agents" 网站提供了许多示例字符串,但如果您的客户的设置范围有限,那么值得尝试每个设置并记录用户代理作为初步步骤。

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-03-27
            • 2019-01-19
            • 2013-01-25
            • 2021-03-06
            相关资源
            最近更新 更多