昨天做了一个简单的显示 c#显示服务器的配置和客户端的配置的页面. 其中的html代码如下: < div align ="center" > < div class ="SysTitle" > 服务器相关信息 </ div > < div > < div class ="AdminContent1" > 服务器IP地址: < asp:Label id ="IpOnServer" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 服务器的主机名: < asp:Label id ="ServerName" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 服务器的DNS别名: < asp:Label id ="DNS" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 服务器处理请求的端口: < asp:Label id ="Stock" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 协议的名称和版本: < asp:Label id ="XieYi" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 服务器的名称和版本: < asp:Label id ="Server_Soft" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 服务器操作系统: < asp:Label id ="OSOnServer" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 脚本超时时间: < asp:Label id ="ScriptTime" runat ="server" > Label </ asp:Label ></ div > </ div > < div class ="SysTitle" > 客户端相关信息 </ div > < div class ="AdminContent1" > IP地址: < asp:Label id ="IpOnClient" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 浏览器: < asp:Label id ="BroswerOnClient" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 主机名称: < asp:Label id ="ServerNameOnClient" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 当前访问地址: < asp:Label id ="UrlNow" runat ="server" > Label </ asp:Label ></ div > < div class ="AdminContent2" > 来访网络: < asp:Label id ="NetName" runat ="server" > Label </ asp:Label ></ div > </ div > cs代码如下: if ( ! Page.IsPostBack) ... { if (Int32.Parse(Session["Priority"].ToString()) > 2) ...{ Response.Write("<script>alert('对不起,您的权限不够,无权访问此页面!');top.location.href='../default.aspx'</script>"); } IPHostEntry OIPHost = Dns.Resolve(Environment.MachineName); if (OIPHost.AddressList.Length > 0) ...{ this.IpOnServer.Text = OIPHost.AddressList[0].ToString(); } this.DNS.Text = OIPHost.HostName; this.ServerName.Text = Environment.MachineName; this.OSOnServer.Text = Environment.OSVersion.ToString(); this.Server_Soft.Text = Request.ServerVariables["SERVER_SOFTWARE"].ToString(); this.Stock.Text = Request.ServerVariables["SERVER_PORT"].ToString(); this.XieYi.Text = Request.ServerVariables["SERVER_PROTOCOL"].ToString(); this.ScriptTime.Text = Server.ScriptTimeout.ToString(); /**/////OnClient this.IpOnClient.Text = Request.UserHostAddress; this.ServerNameOnClient.Text = Request.UserHostName; this.BroswerOnClient.Text =Request.Browser.Type; this.NetName.Text = Environment.UserDomainName; this.UrlNow.Text = Request.RawUrl; 这上面用到了1个命名空间是:using System.Net;获取服务器IP时候用到的