How to get operating system version asp.net
Asked Answered
K

6

6

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..

Kenzi answered 18/2, 2009 at 15:31 Comment(1)
Read my answer below for the most updated solution.Adytum
S
6

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

Schertz answered 18/2, 2009 at 15:36 Comment(0)
B
9

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.

Befitting answered 18/2, 2009 at 15:37 Comment(0)
S
6

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

Schertz answered 18/2, 2009 at 15:36 Comment(0)
A
1

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;
        }
Adytum answered 8/8, 2016 at 11:42 Comment(0)
P
0

The USER_AGENT parameter (on of the request parameters) should tell the story.

Psychometry answered 18/2, 2009 at 15:34 Comment(0)
D
0

i used this and it works just fine. I have used it in one of my apps.

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

Derron answered 26/1, 2010 at 10:36 Comment(1)
don't post just plain links, otherwise your answer is worthless if the link breaks!Topper
M
0
OperatingSystem os = Environment.OSVersion;
var platform = os.Platform.ToString();
var version = os.Version.ToString();
var servicePack = os.ServicePack.ToString();

You can also find with the help of user agent.

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
         }
Mastectomy answered 2/4, 2015 at 5:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.