承接
.NET开发中你可能会用到的常用方法总结。
放在一篇中整理起来比较难受,继续在这里进行添加。
ASP.NET获取服务器信息方法
放在一篇中整理起来比较难受,继续在这里进行添加。
ASP.NET获取服务器信息方法
Code
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->if(!IsPostBack)
{
Label1.Text="服务器名称:"+Server.MachineName;//服务器名称
Label2.Text="服务器IP地址:"+Request.ServerVariables["LOCAL_ADDR"];//服务器IP地址
Label3.Text="服务器域名:"+Request.ServerVariables["SERVER_NAME"];//服务器域名
Label4.Text=".NET解释引擎版本:"+".NETCLR"+Environment.Version.Major+"."+Environment.Version.Minor+"."+Environment.Version.Build+"."+Environment.Version.Revision;//.NET解释引擎版本
Label5.Text="服务器操作系统版本:"+Environment.OSVersion.ToString();//服务器操作系统版本
Label6.Text="服务器IIS版本:"+Request.ServerVariables["SERVER_SOFTWARE"];//服务器IIS版本
Label7.Text="HTTP访问端口:"+Request.ServerVariables["SERVER_PORT"];//HTTP访问端口
Label8.Text="虚拟目录的绝对路径:"+Request.ServerVariables["APPL_RHYSICAL_PATH"];//虚拟目录的绝对路径
Label9.Text="执行文件的绝对路径:"+Request.ServerVariables["PATH_TRANSLATED"];//执行文件的绝对路径
Label10.Text="虚拟目录Session总数:"+Session.Contents.Count.ToString();//虚拟目录Session总数
Label11.Text="虚拟目录Application总数:"+Application.Contents.Count.ToString();//虚拟目录Application总数
Label12.Text="域名主机:"+Request.ServerVariables["HTTP_HOST"];//域名主机
Label13.Text="服务器区域语言:"+Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];//服务器区域语言
Label14.Text="用户信息:"+Request.ServerVariables["HTTP_USER_AGENT"];
Label14.Text="CPU个数:"+Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");//CPU个数
Label15.Text="CPU类型:"+Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER");//CPU类型
Label16.Text="进程开始时间:"+GetPrStart();//进程开始时间
Label17.Text="AspNet内存占用:"+GetAspNetN();//AspNet内存占用
Label18.Text="AspNetCPU时间:"+GetAspNetCpu();//AspNetCPU时间
Label19.Text="FSO文本文件读写:"+Check("Scripting.FileSystemObject");//FSO文本文件读写
Label20.Text="应用程序占用内存"+GetServerAppN();//应用程序占用内存
}
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->if(!IsPostBack)
{
Label1.Text="服务器名称:"+Server.MachineName;//服务器名称
Label2.Text="服务器IP地址:"+Request.ServerVariables["LOCAL_ADDR"];//服务器IP地址
Label3.Text="服务器域名:"+Request.ServerVariables["SERVER_NAME"];//服务器域名
Label4.Text=".NET解释引擎版本:"+".NETCLR"+Environment.Version.Major+"."+Environment.Version.Minor+"."+Environment.Version.Build+"."+Environment.Version.Revision;//.NET解释引擎版本
Label5.Text="服务器操作系统版本:"+Environment.OSVersion.ToString();//服务器操作系统版本
Label6.Text="服务器IIS版本:"+Request.ServerVariables["SERVER_SOFTWARE"];//服务器IIS版本
Label7.Text="HTTP访问端口:"+Request.ServerVariables["SERVER_PORT"];//HTTP访问端口
Label8.Text="虚拟目录的绝对路径:"+Request.ServerVariables["APPL_RHYSICAL_PATH"];//虚拟目录的绝对路径
Label9.Text="执行文件的绝对路径:"+Request.ServerVariables["PATH_TRANSLATED"];//执行文件的绝对路径
Label10.Text="虚拟目录Session总数:"+Session.Contents.Count.ToString();//虚拟目录Session总数
Label11.Text="虚拟目录Application总数:"+Application.Contents.Count.ToString();//虚拟目录Application总数
Label12.Text="域名主机:"+Request.ServerVariables["HTTP_HOST"];//域名主机
Label13.Text="服务器区域语言:"+Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];//服务器区域语言
Label14.Text="用户信息:"+Request.ServerVariables["HTTP_USER_AGENT"];
Label14.Text="CPU个数:"+Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");//CPU个数
Label15.Text="CPU类型:"+Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER");//CPU类型
Label16.Text="进程开始时间:"+GetPrStart();//进程开始时间
Label17.Text="AspNet内存占用:"+GetAspNetN();//AspNet内存占用
Label18.Text="AspNetCPU时间:"+GetAspNetCpu();//AspNetCPU时间
Label19.Text="FSO文本文件读写:"+Check("Scripting.FileSystemObject");//FSO文本文件读写
Label20.Text="应用程序占用内存"+GetServerAppN();//应用程序占用内存
}
ASP.NET获取客户端信息
Code
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->客户端IP:Page.Request.UserHostAddress
用户信息:Page.User;
服务器电脑名称:Page.Server.MachineName
当前用户电脑名称:System.Net.Dns.GetHostName()
当前电脑名:System.Environment.MachineName
当前电脑所属网域:System.Environment.UserDomainName
当前电脑用户:System.Environment.UserName
浏览器类型:Request.Browser.Browser
浏览器标识:Request.Browser.Id
浏览器版本号:Request.Browser.Version
浏览器是不是测试版本:Request.Browser.Beta
浏览器的分辨率(像素):Request["width"].ToString()+"*"+Request["height"].ToString();//1280/1024
客户端的操作系统:Request.Browser.Platform
是不是win16系统:Request.Browser.Win16
是不是win32系统:Request.Browser.Win32
//透过代理取IP
stringGetIp()
{
//可以透过代理服务器
stringuserIP=Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if(userIP==null||userIP=="")
{
//没有代理服务器,如果有代理服务器获取的是代理服务器的IP
userIP=Request.ServerVariables["REMOTE_ADDR"];
}
returnuserIP;
}
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->客户端IP:Page.Request.UserHostAddress
用户信息:Page.User;
服务器电脑名称:Page.Server.MachineName
当前用户电脑名称:System.Net.Dns.GetHostName()
当前电脑名:System.Environment.MachineName
当前电脑所属网域:System.Environment.UserDomainName
当前电脑用户:System.Environment.UserName
浏览器类型:Request.Browser.Browser
浏览器标识:Request.Browser.Id
浏览器版本号:Request.Browser.Version
浏览器是不是测试版本:Request.Browser.Beta
浏览器的分辨率(像素):Request["width"].ToString()+"*"+Request["height"].ToString();//1280/1024
客户端的操作系统:Request.Browser.Platform
是不是win16系统:Request.Browser.Win16
是不是win32系统:Request.Browser.Win32
//透过代理取IP
stringGetIp()
{
//可以透过代理服务器
stringuserIP=Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if(userIP==null||userIP=="")
{
//没有代理服务器,如果有代理服务器获取的是代理服务器的IP
userIP=Request.ServerVariables["REMOTE_ADDR"];
}
returnuserIP;
}
C#实现页面加载
Code
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->protectedvoidPage_Load(objectsender,EventArgse)
{
Loading();
}
publicvoidLoading()
{
HttpContexthc=HttpContext.Current;
//创建一个页面居中的div
hc.Response.Write("<divid='loading'style='position:absolute;height:100px;text-align:center;z-index:9999;left:50%;top:50%;margin-top:-50px;margin-left:-175px;'>");
hc.Response.Write("<br/>页面正在加载中,请稍候<br/><br/>");
hc.Response.Write("<tableborder='0'cellpadding='0'cellspacing='0'style='background-image:url(images/Progress/plan-bg.gif);text-align:center;width:300px;'>");
hc.Response.Write("<tr><tdstyle='height:20px;text-align:center'><marqueedirection='right'scrollamount='30'width='290px'><imgheight='10'src='images/Progress/plan-wait.gif'width='270'/>");
hc.Response.Write("</marquee></td></tr></table></div>");
//hc.Response.Write("<script>mydiv.innerText='';</script>");
hc.Response.Write("<scripttype=text/javascript>");
//最重要是这句了,重写文档的onreadystatechange事件,判断文档是否加载完毕
hc.Response.Write("functiondocument.onreadystatechange()");
hc.Response.Write(@"{try
{
if(document.readyState=='complete')
{
delNode('loading');
}
}
catch(e)
{
alert('页面加载失败');
}
}
functiondelNode(nodeId)
{
try
{
vardiv=document.getElementById(nodeId);
if(div!==null)
{
div.parentNode.removeChild(div);
div=null;
CollectGarbage();
}
}
catch(e)
{
alert('删除ID为'+nodeId+'的节点出现异常');
}
}
");
hc.Response.Write("</script>");
hc.Response.Flush();
}
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->protectedvoidPage_Load(objectsender,EventArgse)
{
Loading();
}
publicvoidLoading()
{
HttpContexthc=HttpContext.Current;
//创建一个页面居中的div
hc.Response.Write("<divid='loading'style='position:absolute;height:100px;text-align:center;z-index:9999;left:50%;top:50%;margin-top:-50px;margin-left:-175px;'>");
hc.Response.Write("<br/>页面正在加载中,请稍候<br/><br/>");
hc.Response.Write("<tableborder='0'cellpadding='0'cellspacing='0'style='background-image:url(images/Progress/plan-bg.gif);text-align:center;width:300px;'>");
hc.Response.Write("<tr><tdstyle='height:20px;text-align:center'><marqueedirection='right'scrollamount='30'width='290px'><imgheight='10'src='images/Progress/plan-wait.gif'width='270'/>");
hc.Response.Write("</marquee></td></tr></table></div>");
//hc.Response.Write("<script>mydiv.innerText='';</script>");
hc.Response.Write("<scripttype=text/javascript>");
//最重要是这句了,重写文档的onreadystatechange事件,判断文档是否加载完毕
hc.Response.Write("functiondocument.onreadystatechange()");
hc.Response.Write(@"{try
{
if(document.readyState=='complete')
{
delNode('loading');
}
}
catch(e)
{
alert('页面加载失败');
}
}
functiondelNode(nodeId)
{
try
{
vardiv=document.getElementById(nodeId);
if(div!==null)
{
div.parentNode.removeChild(div);
div=null;
CollectGarbage();
}
}
catch(e)
{
alert('删除ID为'+nodeId+'的节点出现异常');
}
}
");
hc.Response.Write("</script>");
hc.Response.Flush();
}
Http请求图片显示:
Code
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->publicImagebyteArrayToImage()
{
WebRequestmyWebRequest=WebRequest.Create("图片地址");
using(WebResponsemyWebResponse=myWebRequest.GetResponse())
{using(StreamReceiveStream=myWebResponse.GetResponseStream()){byte[]byteArrayIn=newbyte[ReceiveStream.Length];
using(MemoryStreamms=newMemoryStream(byteArrayIn))
{
Image.FromStream(ms);
}
}
}
}
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->publicImagebyteArrayToImage()
{
WebRequestmyWebRequest=WebRequest.Create("图片地址");
using(WebResponsemyWebResponse=myWebRequest.GetResponse())
{using(StreamReceiveStream=myWebResponse.GetResponseStream()){byte[]byteArrayIn=newbyte[ReceiveStream.Length];
using(MemoryStreamms=newMemoryStream(byteArrayIn))
{
Image.FromStream(ms);
}
}
}
}