1

Okay, so I am working on an ASP.Net website (C# code behind) where, for troubleshooting reasons (most of our clients that call for tech support don't know what OS/Browser/BrowserVersion they are using), we want to log a "system profile" so to speak so that we can more easily troubleshoot OS/Browser related issues.

Currently, I am using Request.UserAgent. The problem with this is that it returns a string that is unhelpful to our support staff:

Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0

What I want to do is to pull just the OS (Windows NT 6.1, or whatever OS the user has) by itself, without the additional browser information, as I am already segregating other system information as such:

| UserID | UserOS | BrowserType | BrowserName | MajorVersion | MinorVersion | IsBeta |

| 11111 | userOS* | * Firefox24.0 * | * * Firefox * * |* * * * * 24 * * * * |* * * * 0 * * * * | * * 0 * *|

Is it possible just to get the OS by itself?

Bonus points if you know how to get the OS Friendly name from a client machine (i.e. Windows 7 vs Windows NT 6.1), this would save me from having to create a separate database of OS numbers.

Jeff Beese
  • 388
  • 2
  • 5
  • 19
  • [Is httpcapabilities where you're looking for?](http://msdn.microsoft.com/en-us/library/system.web.configuration.httpcapabilitiesbase.platform(v=vs.110).aspx) – rene Oct 31 '13 at 18:42
  • httpcapabilities is what I am using to segregate the rest of the data, but I haven't seen anything in there that will give me the OS. It does have `Platform` but all that produces is WinNT, no version to identify the specific OS. – Jeff Beese Oct 31 '13 at 18:46
  • possible duplicate of [DotNet Get User Operating System (HTTP\_USER\_AGENT)](http://stackoverflow.com/questions/2442935/dotnet-get-user-operating-system-http-user-agent) – rene Oct 31 '13 at 18:53
  • This gets me the same result i was already getting. – Jeff Beese Oct 31 '13 at 19:08

1 Answers1

4

The User Agent is not going to give you a friendly name so you will need to maintain a list, something along the lines of this should work...

        Dictionary<string, string> osList = new Dictionary<string, string>
        {
            {"Windows NT 6.3", "Windows 8.1"},
            {"Windows NT 6.2", "Windows 8"},
            {"Windows NT 6.1", "Windows 7"},
            {"Windows NT 6.0", "Windows Vista"},
            {"Windows NT 5.2", "Windows Server 2003"},
            {"Windows NT 5.1", "Windows XP"},
            {"Windows NT 5.0", "Windows 2000"}
        };

        string userAgentText = HttpContext.Current.Request.UserAgent;

        if (userAgentText != null)
        {
            int startPoint = userAgentText.IndexOf('(') + 1;
            int endPoint = userAgentText.IndexOf(';');

            string osVersion = userAgentText.Substring(startPoint, (endPoint - startPoint));
            string friendlyOsName = osList[osVersion];
        }
user2315985
  • 2,848
  • 5
  • 17
  • 18
  • Thank you, the second part is precisely what I was looking for. As far as the friendly name goes, maintaining a list isn't a viable option as there are just too many operating systems to consider (Windows, Apple, Linux/Unix, Mobile) that would have to be included, especially in the code where you have to recompile the code every time the list gets updated. I believe just being able to get the version number out (as you have done), and then Googling it to find out the OS will have to be the way it works. Thank you much. – Jeff Beese Nov 01 '13 at 13:01
  • 1
    No problem. This list might help you as you have to look up the details of each OS http://user-agent-string.info/list-of-ua/os – user2315985 Nov 01 '13 at 13:24