为什么80%的码农都做不了架构师?>>>
获取服务端和客户端信息
获取服务器名:Page.Server.ManchineName
获取用户信息:Page.User
获取客户端电脑名:Page.Request.UserHostName
获取客户端IP:Page.Request.UserHostAddress
protectedvoidPage_Load(objectsender,EventArgse)
{
//将客户端的信息添加到Dictionary中
Dictionary<string,string>clientInfos=newDictionary<string,string>();
try
{
stringip=Request.UserHostAddress;
stringuserAgent=Request.UserAgent==null?"无":Request.UserAgent;
if(Request.ServerVariables["HTTP_UA_CPU"]==null)
clientInfos.Add("CPU类型","未知");
else
clientInfos.Add("CPU类型",Request.ServerVariables["HTTP_UA_CPU"]);
clientInfos.Add("操作系统",this.GetOSNameByUserAgent(userAgent));
clientInfos.Add("IP地址",ip);
if(Request.Browser.ClrVersion==null)
clientInfos.Add(".NETCLR版本","不支持");
else
clientInfos.Add(".NETCLR版本",Request.Browser.ClrVersion.ToString());
clientInfos.Add("浏览器",Request.Browser.Browser+Request.Browser.Version);
clientInfos.Add("支持ActiveX",Request.Browser.ActiveXControls?"支持":"不支持");
clientInfos.Add("支持Cookies",Request.Browser.Cookies?"支持":"不支持");
clientInfos.Add("支持CSS",Request.Browser.SupportsCss?"支持":"不支持");
clientInfos.Add("语言",Request.UserLanguages[0]);
stringhttpAccept=Request.ServerVariables["HTTP_ACCEPT"];
if(httpAccept==null)
clientInfos.Add("计算机/手机","未知");
elseif(httpAccept.IndexOf("wap")>-1)
clientInfos.Add("计算机/手机","手机");
else
clientInfos.Add("计算机/手机","计算机");
clientInfos.Add("Platform",Request.Browser.Platform);
clientInfos.Add("Win16",Request.Browser.Win16?"是":"不是");
clientInfos.Add("Win32",Request.Browser.Win32?"是":"不是");
if(Request.ServerVariables["HTTP_ACCEPT_ENCODING"]==null)
clientInfos.Add("HttpAcceptEncoding","无");
else
clientInfos.Add("HttpAcceptEncoding",Request.ServerVariables["HTTP_ACCEPT_ENCODING"]);
clientInfos.Add("UserAgent",userAgent);
}
catch(Exceptionex)
{
Response.Write(ex.Message);
}
//根据Dictionary中的内容在Table中显示客户端信息
this.Response.Write("<tablecellpadding=0cellspacing=0>");
this.Response.Write("<tr>");
this.Response.Write("<tdwidth=145>项目</td>");
this.Response.Write("<td>值</td>");
this.Response.Write("</tr>");
foreach(stringkeyinclientInfos.Keys)
{
this.Response.Write("<tr>");
this.Response.Write("<td>"+key+"</font></td>");
this.Response.Write("<td>"+clientInfos[key].ToString()+"</td>");
this.Response.Write("</tr>");
}
this.Response.Write("</table>");
}
///<summary>
///根据UserAgent获取操作系统名称
///</summary>
privatestringGetOSNameByUserAgent(stringuserAgent)
{
stringosVersion="未知";
if(userAgent.Contains("NT6.0"))
{
osVersion="WindowsVista/Server";
}
elseif(userAgent.Contains("NT5.2"))
{
osVersion="WindowsServer";
}
elseif(userAgent.Contains("NT5.1"))
{
osVersion="WindowsXP";
}
elseif(userAgent.Contains("NT5"))
{
osVersion="Windows2000";
}
elseif(userAgent.Contains("NT4"))
{
osVersion="WindowsNT4";
}
elseif(userAgent.Contains("Me"))
{
osVersion="WindowsMe";
}
elseif(userAgent.Contains("98"))
{
osVersion="Windows98";
}
elseif(userAgent.Contains("95"))
{
osVersion="Windows95";
}
elseif(userAgent.Contains("Mac"))
{
osVersion="Mac";
}
elseif(userAgent.Contains("Unix"))
{
osVersion="UNIX";
}
elseif(userAgent.Contains("Linux"))
{
osVersion="Linux";
}
elseif(userAgent.Contains("SunOS"))
{
osVersion="SunOS";
}
returnosVersion;
}