In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to get the operating system version and browser version of the client as well as the IP address in .NET, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
When we use .NET as a website, in many cases we need to know the operating system version and browser version of the client. How to get the operating system and browser version of the client? We can get it by analyzing the UserAgent.
.net gets the operating system of the client
Looking at the following code, we first create a method to get the operating system by analyzing the UserAgent
/ public static string GetOSNameByUserAgent (string userAgent) {string osVersion = "unknown"; if (userAgent.Contains ("NT 10.0") {osVersion = "Windows 10";} else if (userAgent.Contains ("NT 6.3")) {osVersion = "Windows 8.1";} else if (userAgent.Contains ("NT 6.2")) {osVersion = "Windows 8" } else if (userAgent.Contains ("NT 6 1")) {osVersion = "Windows 7";} else if (userAgent.Contains ("NT 6 1")) {osVersion = "Windows 7";} else if (userAgent.Contains ("NT 6 0")) {osVersion = "Windows Vista/Server 2008";} else if (userAgent.Contains ("NT 5.2")) {if (userAgent.Contains ("64") osVersion = "Windows XP"; else osVersion = "Windows Server 2003") } else if (userAgent.Contains ("NT 5")) {osVersion = "Windows XP";} else if (userAgent.Contains ("NT 5")) {osVersion = "Windows 2000";} else if (userAgent.Contains ("NT4")) {osVersion = "Windows NT4";} else if (userAgent.Contains ("Me")) {osVersion = "Windows Me";} else if (userAgent.Contains ("98")) {osVersion = "Windows 98" } else if (userAgent.Contains ("95")) {osVersion = "Windows 95";} else if (userAgent.Contains ("Mac")) {osVersion = "Mac";} else if (userAgent.Contains ("Unix")) {osVersion = "UNIX";} else if (userAgent.Contains ("Linux")) {osVersion = "Linux";} else if (userAgent.Contains ("SunOS")) {osVersion = "SunOS";} else {osVersion = System.Web.HttpContext.Current.Request.Browser.Platform } return osVersion;}
The above method is to parse the operating system string information contained in UserAgent and return the specific operating system and version. Request.Browser.Platform is the kernel of the operating system. If none of the above matches, you can directly return the kernel version of the operating system. The above method can detect the latest Windows 10 and mainstream operating systems such as Apple, Linux, SunOS and so on.
To call the method, we can write something like this:
The copy code is as follows:
String systemName = GetOSNameByUserAgent (System.Web.HttpContext.Current.Request.UserAgent)
By passing in the UserAgent of Request, you can return to the operating system.
.net get the browser version of the client
.net to get the browser version is simple, just through the Browser inherent property of request, as shown in the following code
The copy code is as follows:
String browserName = System.Web.HttpContext.Current.Request.Browser.Browser + "" + System.Web.HttpContext.Current.Request.Browser.Version
.net to obtain the IP address:
/ obtain the current client Ip address / public static string GetCurrentUserHostAddress () {string userHostAddress = ""; userHostAddress = System.Web.HttpContext.Current.Request.ServerVariables ["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty (userHostAddress)) {/ / if there is no proxy IP, directly fetch the connecting client IP userHostAddress = System.Web.HttpContext.Current.Request.ServerVariables ["REMOTE_ADDR"];} return userHostAddress } is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.