How to get operating system version asp.net

23,049

Solution 1

The gist of it is use Request.Browser.Platform, and the version is in Request.UserAgent.

Solution 2

Use Request.UserAgent - that will probably give all the information you need.

There's a "List of User-Agents" web site which gives lots of sample strings, but if your client has a limited range of setups, it would be worth just trying each of them and logging the user agent as a preliminary step.

Be aware that many browsers will allow you to "spoof" the user agent string, so you mustn't use this for security purposes - but it sounds as if your use case is pretty reasonable.

Solution 3

Since the selected answer is not up to date and supplied a broken link I have decided to publish the way I accomplished it:

I installed 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 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;
        }
Share:
23,049
mehmetserif
Author by

mehmetserif

Updated on October 25, 2020

Comments

  • mehmetserif
    mehmetserif over 3 years

    I want to get the os version that the browser opens, actually my project is an asp.net project and i want to know which operating system runs on the client but there is a question about it. Because the client will use xp but at the same time will use Windows CE 5.0, so the internet explorer in Windows CE is not as good as the one in xp, because of it i'll redirect the user to the page that i designed for Windows CE. So is there any solution to do it?

    Thank you..

  • sra
    sra over 12 years
    don't post just plain links, otherwise your answer is worthless if the link breaks!