简体   繁体   中英

How to get operating system version asp.net

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

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.

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

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

USER_AGENT参数(在请求参数上)应该讲述故事。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM