问题描述
PerformanceCountercpu=newPerformanceCounter("Processor","%ProcessorTime","_Total");varpercentage=cpu.NextValue();我用以上代码获取服务器CPU,发布在本机IIS,本机访问或其他机器访问都可以,但是发布到服务器上就有异常。请问下这是什么原因,在线求助。
解决方案
解决方案二:
解决方案三:
应该是权限问题。服务器是运营商的话,请他们帮你。
解决方案四:
有出错的截图吗上传,不然都是瞎猜
解决方案五:
解决方案六:
需要桌面权限
解决方案七:
放到page之前去运行就可以了usingSystem;usingSystem.IO;usingSystem.Text.RegularExpressions;usingSystem.Threading;usingSystem.Web;usingSystem.Xml;usingGalsun.Common;usingGalsun.HH.FCX.Content;usingGalsun.HH.FCX.Mode;usingSystem.Data;usingSystem.Management;namespaceGalsun.HH.FCX.Web.UI{publicclassHttpModule:System.Web.IHttpModule{///<summary>///实现接口的Init方法///</summary>///<paramname="context"></param>publicvoidInit(HttpApplicationcontext){GetHardID();}///<summary>///获取硬盘ID///</summary>///<returns>硬盘ID</returns>publicstaticstringGetHardID(){stringHDInfo="";ManagementClasscimobject1=newManagementClass("Win32_DiskDrive");ManagementClasscimobject2=newManagementClass("Win32_Processor");try{ManagementObjectCollectionmoc1=cimobject1.GetInstances();foreach(ManagementObjectmoinmoc1){HDInfo+=(string)mo.Properties["Model"].Value;break;}ManagementObjectCollectionmoc2=cimobject2.GetInstances();foreach(ManagementObjectmoinmoc2){HDInfo+=(string)mo.Properties["Processorid"].Value;break;}}catch(Exceptionerr){HDInfo=err.ToString();}if(System.Web.HttpContext.Current.Application["HDInfo"]==null){System.Web.HttpContext.Current.Application.Lock();System.Web.HttpContext.Current.Application["HDInfo"]=HDInfo;System.Web.HttpContext.Current.Application.UnLock();}returnHDInfo;}publicvoidApplication_OnError(Objectsender,EventArgse){HttpApplicationapplication=(HttpApplication)sender;HttpContextcontext=application.Context;//if(context.Server.GetLastError().GetBaseException()isMyException){//MyExceptionex=(MyException)context.Server.GetLastError().GetBaseException();context.Response.Write("<html><bodystyle="font-size:14px;">");context.Response.Write("GL.CMSError:<br/>");context.Response.Write("<textareaname="errormessage"style="width:80%;height:200px;word-break:break-all">");context.Response.Write(System.Web.HttpUtility.HtmlEncode(context.Server.GetLastError().ToString()));context.Response.Write("</textarea>");context.Response.Write("</body></html>");context.Response.End();}}///<summary>///实现接口的Dispose方法///</summary>publicvoidDispose(){}}}web.config<httpModules><addtype="Galsun.Easy.Web.UI.Base.HttpModule"name="HttpModule"/></httpModules>