Obtain client parameter operating system information in ASP.net

Source: Internet
Author: User

Copy codeThe Code is as follows:
/// <Summary>
/// Obtain the user's operating system information
/// </Summary>
/// <Returns> </returns>
Public string GetUserOS ()
{
String strSysVersion = "other ";
HttpRequest Request = HttpContext. Current. Request;
String strAgentInfo = Request. ServerVariables ["HTTP_USER_AGENT"];

If (strAgentInfo. Contains ("NT 6.0 "))
{
StrSysVersion = "Windows Vista ";
}
Else if (strAgentInfo. Contains ("NT 5.2 "))
{
StrSysVersion = "Windows 2003 ";
}
Else if (strAgentInfo. Contains ("NT 5.1 "))
{
StrSysVersion = "Windows XP ";
}
Else if (strAgentInfo. Contains ("NT 5 "))
{
StrSysVersion = "Windows 2000 ";
}
Else if (strAgentInfo. Contains ("NT 4.9 "))
{
StrSysVersion = "Windows ME ";
}
Else if (strAgentInfo. Contains ("NT 4 "))
{
StrSysVersion = "Windows NT4 ";
}
Else if (strAgentInfo. Contains ("NT 98 "))
{
StrSysVersion = "Windows 98 ";
}
Else if (strAgentInfo. Contains ("NT 95 "))
{
StrSysVersion = "Windows 95 ";
}
Else if (strSysVersion. ToLower (). Contains ("Mac "))
{
StrSysVersion = "Mac ";
}
Else if (strSysVersion. ToLower (). Contains ("unix "))
{
StrSysVersion = "UNIX ";
}
Else if (strSysVersion. ToLower (). Contains ("linux "))
{
StrSysVersion = "Linux ";
}
Else if (strSysVersion. Contains ("SunOS "))
{
StrSysVersion = "SunOS ";
}
Return strSysVersion;
}


/// <Summary>
/// Obtain the browser type and version of the Client
/// </Summary>
/// <Returns> </returns>
Public string GetUserBrowser ()
{
String strBrowser = "other ";
HttpRequest Request = HttpContext. Current. Request;
String strAgentInfo = Request. ServerVariables ["HTTP_USER_AGENT"];
If (Regex. IsMatch (strAgentInfo, "MSIE ([// d] //. [// d])", RegexOptions. IgnoreCase | RegexOptions. Compiled ))
{
StrBrowser = Regex. Match (strAgentInfo, "MSIE ([// d] //. [// d])"). Result ("IE: $1 ");
}
Else if (Regex. IsMatch (strAgentInfo, "Opera ([// d] //. [// d])", RegexOptions. IgnoreCase | RegexOptions. Compiled ))
{
StrBrowser = Regex. Match (strAgentInfo, "Opera ([// d] //. [// d])"). Result ("Opera: $1 ");
}
Else if (Regex. IsMatch (strAgentInfo, "Opera // ([// d] //. [// d])", RegexOptions. IgnoreCase | RegexOptions. Compiled ))
{
StrBrowser = Regex. match (strAgentInfo, "Opera // ([// d] //. [// d]) "). result ("Opera: $1 ");
}
Else if (Regex. IsMatch (strAgentInfo, "Firefox // ([// d] //. [// d])", RegexOptions. IgnoreCase | RegexOptions. Compiled ))
{
StrBrowser = Regex. match (strAgentInfo, "Firefox /// ([// d] //. [// d]) "). result ("Firefox: $1 ");
}
Return strBrowser;
}

# Region GetIP ()
/// <Summary>
/// Obtain the IP address
/// </Summary>
/// <Returns> </returns>
Public string GetIP ()
{
String uip = "";
If (HttpContext. Current. Request. ServerVariables ["HTTP_VIA"]! = Null)
{
Uip = HttpContext. Current. Request. ServerVariables ["HTTP_X_FORWARDED_FOR"]. ToString ();
}
Else
{
Uip = HttpContext. Current. Request. ServerVariables ["REMOTE_ADDR"]. ToString ();
}
Return uip;
}
# Endregion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.