簡體   English   中英

如何獲得操作系統版本的asp.net

[英]How to get operating system version asp.net

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

謝謝..

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

有一個“用戶代理列表”網站提供了大量的示例字符串,但如果您的客戶端設置范圍有限,那么只需嘗試每個設置並記錄用戶代理作為初步步驟。

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

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

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

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

鏈接到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;
        }

我用過它,效果很好。 我在我的一個應用程序中使用過它。

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

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
         }

USER_AGENT參數(在請求參數上)應該講述故事。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM