繁体   English   中英

ASP.NET MVC:创建性能计数器时拒绝请求的注册表访问

[英]ASP.NET MVC: Requested registry access denied when creating performance counters

我试图为我的MVC操作创建性能计数器,并收到一个SecurityException,说注册表访问被拒绝。 我已将完全信任添加到我的web.config文件中,但这不能解决问题。

PerformanceCounterCategory performancecountercategory = null;
if (!PerformanceCounterCategory.Exists(categoryname))
{
    performancecountercategory = PerformanceCounterCategory.Create(categoryname, "Latency counters for the 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" />

这不是中等信任/完全信任问题。 您需要以管理员或其他特权用户身份运行才能在计算机上创建性能计数器。 请参阅http://msdn.microsoft.com/zh-cn/library/system.diagnostics.performancecountercategory(v=vs.110).aspx的备注部分:

强烈建议在应用程序安装期间而不是在应用程序执行期间创建新的性能计数器类别。

基本上,如果您的应用程序具有安装程序,则在安装时调用PerformanceCounterCategory.Create。 如果您的应用程序没有安装程序,则可以使用此代码编写.exe并从提升的命令提示符下运行它。

然后,作为MVC应用程序正常执行的一部分,您可以利用标准PerformanceCounter类打开该计数器并向其中写入值,从而利用该性能计数器已经存在的事实。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM