c# - ASP.NET MVC: Requested registry access denied when creating performance counters -
i'm attempting create performance counters mvc actions , receive securityexception saying registry access denied. i've added full-trust web.config file, not solve problem.
performancecountercategory performancecountercategory = null; if (!performancecountercategory.exists(categoryname)) { performancecountercategory = performancecountercategory.create(categoryname, "latency counters media gateway", performancecountercategorytype.singleinstance, countercreationdata); } else { performancecountercategory = new performancecountercategory(constants.performancecountercategory); } <system.web> <trust level="full"></trust> <compilation targetframework="4.5" debug="true" /> <httpruntime targetframework="4.5" />
this isn't medium trust / full trust issue. need running administrator or other privileged user create performance counters on machine. see remarks section of http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecountercategory(v=vs.110).aspx:
it recommended new performance counter categories created during installation of application, not during execution of application.
basically, if application has installer, you'd call performancecountercategory.create @ installation time. if application doesn't have installer, can write .exe code , run elevated command prompt.
then, part of mvc application's normal execution, can take advantage of fact performance counter exists using standard performancecounter class open counter , write values it.
Comments
Post a Comment