我正在尝试编写一些c#代码,如果不存在则编写一个新的性能计数器类别,然后添加一个特定的计数器。当我从Visual Studio开发服务器运行此代码时,一切正常。当我将其部署到IIS并尝试使用时,出现权限错误。我正在运行Windows 7并使用IIS 7.5。
到目前为止,我已经完成了一些工作,其中一些是出于绝望而完成的:
我知道这些步骤已经部分起作用,因为我现在可以检查类别是否存在(ASPNET用户甚至无法做到这一点)。我可以检查某个类别是否存在,我无法添加一个新类别。
我得到的错误是
Cannot create or delete the Performance Category 'C:\Windows\TEMP\tmp1AA8.tmp' because access is denied.
添加性能计数器类别的代码如下所示:
if (!PerformanceCounterCategory.Exists("APIService"))
{
CounterCreationDataCollection counters = new CounterCreationDataCollection();
CounterCreationData counter = new CounterCreationData();
counter.CounterName = "# of operations executed";
counter.CounterHelp = "Operations executed";
counter.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
counters.Add(counter);
PerformanceCounterCategory.Create("APIService", "Api Counter", PerformanceCounterCategoryType.SingleInstance, counters); // This code blows up
}
我搜寻了高低,找不到任何有相同问题的人。我什至尝试让所有人完全控制c:\ windows \ temp。知道我在这里可能会缺少什么吗?
我想我已经找到了解决方案(或者是其他人做了,但是今天早上我可以找到该论坛的链接)。我没有将应用程序池设置为以管理员身份运行,而是将其切换为本地系统用户。这似乎已经解决了所有问题,因为用户拥有足够的权限来编写性能指标以及需要完成的所有其他操作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句