how do I detect user operating system

前端 未结 11 932
难免孤独
难免孤独 2020-12-01 03:58

I have the following code to obtain user details:

HttpBrowserCapabilities bc = HttpContext.Current.Request.Browser;
string UserAgent = HttpContext.Current.Re         


        
11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 04:12

    There is a cool tool named: https://github.com/ua-parser/uap-csharp
    that parse the user agent to OS,Browser,Browser version etc...
    Link to Nuget

    And this is how used it:

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

提交回复
热议问题