Get client parameter operating system information in asp.net

Source: Internet
Author: User
Tags get ip httpcontext servervariables

  This article mainly introduces how to obtain the client parameters or operating system information in asp.net, the need for friends can refer to the following

  Code as follows:///<summary> ///Get user operating System Information  ///</summary> ///<returns></returns& gt;  public String Getuseros ()   {  string strsysversion = "Other";  httprequest Request = httpcontext.cur Rent. 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"; }  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; "}  else if (Stragentinfo.contains ("NT)")   {  strsysversion = "Windows 95";  }  Else if (Strsysversion.tolower (). Contains ("Mac"))   {  strsysversion = "Mac"; }  else if (strsysversion.tolower). Contains ("Unix"))   {  strsysversion = "Unix"; }  else if (). Contains ("Linux"))   {  strsysversion = "Linux"; }  else if ("Strsysversion.contains")   {  strsysversion = "SunOS"; }  return strsysversion; }     ///<summary&gt ; ///Get client browser type and version  ///</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>& nbsp Get ip ///</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.