Asp.net obtains client browser and host information, and asp.net Client

Source: Internet
Author: User
Tags servervariables open source cms

Asp.net obtains client browser and host information, and asp.net Client

Online Preview:
Http://tool.hovertree.com/info/client/

The control code of the aspx page:

<asp:ListBox runat="server" ID="lbHoverTreeInfo" ClientIDMode="Static"> </asp:ListBox>

The following is the implementation code:

1 using System; 2 using System. web; 3 using System. web. UI; 4 5 namespace HoverTreeTool. hvtInfo. keleyiClient 6 {7 public partial class Index: System. web. UI. page 8 {9 protected void Page_Load (object sender, EventArgs e) 10 {11 string userAgent = Request. userAgent = null? "None": Request. UserAgent; 12 if (! IsPostBack) 13 {lbHoverTreeInfo. items. add ("your system information is:"); 14 lbHoverTreeInfo. items. add ("Client IP [Page. request. userHostAddress]: "+ Page. request. userHostAddress); 15 lbHoverTreeInfo. items. add ("browser type [Request. browser. browser]: "+ Request. browser. browser); 16 lbHoverTreeInfo. items. add ("browser ID [Request. browser. id]: "+ Request. browser. id); 17 lbHoverTreeInfo. items. add ("browser version number [Request. browser. version]: "+ Request. browser. version); 18 lbHoverTreeInfo. items. add ("is the browser a test version? [Request. browser. beta]: "+ Request. browser. beta); 19 lbHoverTreeInfo. items. add ("browser type [Request. browser. type]: "+ Request. browser. type); 20 lbHoverTreeInfo. items. add ("whether the framework webpage is supported [Request. browser. frames]: "+ Request. browser. frames); 21 lbHoverTreeInfo. items. add ("whether Cookie [Request. browser. cookies]: "+ Request. browser. cookies); 22 lbHoverTreeInfo. items. add ("browser JScript version [Request. browser. JScriptVersion]: "+ Request. browser. JScriptVersion); 23 lbHoverTreeInfo. items. add ("Screen Resolution width [System. windows. forms. screen. primaryScreen. bounds. width]: "+ System. windows. forms. screen. primaryScreen. bounds. width); 24 lbHoverTreeInfo. items. add ("high screen resolution [System. windows. forms. screen. primaryScreen. bounds. height]: "+ System. windows. forms. screen. primaryScreen. bounds. height); 25 lbHoverTreeInfo. items. add ("browser type [Request. browser. type]: "+ Request. browser. type); 26 lbHoverTreeInfo. items. add ("Client IP [GetHoverTreeIp ()]:" + GetHoverTreeIp (); 27 lbHoverTreeInfo. items. add ("client operating system [Request. browser. platform]: "+ Request. browser. platform); 28 lbHoverTreeInfo. items. add ("client operating system [GetHoverTreeOSName (userAgent)]:" + GetHoverTreeOSName (userAgent); 29 lbHoverTreeInfo. items. add ("Is it a win16 system [Request. browser. win16]: "+ Request. browser. win16); 30 lbHoverTreeInfo. items. add ("Is it win32 system [Request. browser. win32]: "+ Request. browser. win32); 31 lbHoverTreeInfo. items. add ("client. NET Framework Version: Request. browser. clrVersion]: "+ Request. browser. clrVersion); 32 lbHoverTreeInfo. items. add ("whether Java [Request. browser. javaApplets]: "+ Request. browser. javaApplets); 33 34 if (Request. serverVariables ["HTTP_UA_CPU"] = null) 35 lbHoverTreeInfo. items. add ("CPU type [Request. serverVariables [\ "HTTP_UA_CPU \"]: Unknown "); 36 else 37 lbHoverTreeInfo. items. add ("CPU type [Request. serverVariables [\ "HTTP_UA_CPU \"]: "+ Request. serverVariables ["HTTP_UA_CPU"]); 38 39 lbHoverTreeInfo. items. add ("UserAgent information [Request. userAgent]: "+ userAgent); 40 lbHoverTreeInfo. items. add ("By he asked the tool http://tool.hovertree.com/info/client/ "); 41 42} 43} 44 45 // <summary> 46 // obtain the real IP address 47 /// </summary> 48 /// <returns> </returns> 49 public string GetHoverTreeIp () 50 {51 string result = HttpContext. current. request. serverVariables ["HTTP_X_FORWARDED_FOR"]; 52 if (null = result | result = String. empty) 53 {54 result = HttpContext. current. request. serverVariables ["REMOTE_ADDR"]; 55} 56 if (null = result | result = String. empty) 57 {58 result = HttpContext. current. request. userHostAddress; 59} 60 return result; 61} 62 63 // <summary> 64 // obtain the operating system name 65 based on the User Agent // </summary> 66 private string GetHoverTreeOSName (string userAgent) 67 {68 string m_hvtOsVersion = "unknown"; 69 if (userAgent. contains ("NT 6.4") 70 {71 m_hvtOsVersion = "Windows 10"; 72} 73 else 74 if (userAgent. contains ("NT 6.3") 75 {76 m_hvtOsVersion = "Windows 8.1"; 77} 78 else 79 if (userAgent. contains ("NT 6.2") 80 {81 m_hvtOsVersion = "Windows 8"; 82} 83 else 84 if (userAgent. contains ("NT 6.1") 85 {86 m_hvtOsVersion = "Windows 7"; 87} else 88 if (userAgent. contains ("NT 6.0") 89 {90 m_hvtOsVersion = "Windows Vista/Server 2008"; 91} 92 else if (userAgent. contains ("NT 5.2") 93 {94 m_hvtOsVersion = "Windows Server 2003"; 95} 96 else if (userAgent. contains ("NT 5.1") 97 {98 m_hvtOsVersion = "Windows XP"; 99} 100 else if (userAgent. contains ("NT 5") 101 {102 m_hvtOsVersion = "Windows 2000"; 103} 104 else if (userAgent. contains ("NT 4") 105 {106 m_hvtOsVersion = "Windows NT4"; 107} 108 else if (userAgent. contains ("Me") 109 {110 m_hvtOsVersion = "Windows Me"; 111} 112 else if (userAgent. contains ("98") 113 {114 m_hvtOsVersion = "Windows 98"; 115} 116 else if (userAgent. contains ("95") 117 {118 m_hvtOsVersion = "Windows 95"; 119} 120 else if (userAgent. contains ("Mac") 121 {122 m_hvtOsVersion = "Mac"; 123} 124 else if (userAgent. contains ("Unix") 125 {126 m_hvtOsVersion = "UNIX"; 127} 128 else if (userAgent. contains ("Linux") 129 {130 m_hvtOsVersion = "Linux"; 131} 132 else if (userAgent. contains ("SunOS") 133 {134 m_hvtOsVersion = "SunOS"; 135} 136 return m_hvtOsVersion; 137} 138} 139}

Reprinted from: http://hovertree.com/hvtart/bjae/n9f5pp4r.htm

Development Technology Article: http://www.cnblogs.com/sosoft/p/kaifajishu.html

ASP. NET Open Source CMS http://www.cnblogs.com/sosoft/p/cms.html

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.