c# - IIS7 应用程序内 WMI 自定义性能标记的权限问题

标签 c# iis-7 wmi perfmon

我在获取权限以允许我的应用程序(在 IIS7 应用程序池中运行)删除/添加性能计数器类别及其数据时遇到问题。我有这样的代码:

if (!PerformanceCounterCategory.Exists(CategoryName))
{
    var counters = new CounterCreationDataCollection();
    var opsIn = new CounterCreationData
    {
        CounterName = "Test Counter",
        CounterHelp = "Test Counter Help",
        CounterType = PerformanceCounterType.RateOfCountsPerSecond32
    };
    counters.Add(opsIn);

    PerformanceCounterCategory.Create(CategoryName, "Service Layer Instrumentation",
                                      PerformanceCounterCategoryType.SingleInstance,
                                      counters);
}

目的是在尚未创建性能计数器的系统上创建性能计数器,因此我不受静态安装程序行为的约束(我希望能够轻松地更改计数器)。到目前为止,当它起作用时,效果很好。

当我以管理员身份在可执行文件中运行此代码时,没有任何问题。但是,当我在 IIS 服务中运行它时,AppPool 没有执行类别更改的正确权限。我知道一个事实是,可以让 WMI 权限正常工作,因为我之前在测试服务器的演示中做过一次……但那是几个月前的事了,我很累,这是最后一刻。整个事情都变得模糊了。现在我无法重现我的结果,因为我要回去尝试规范安装过程以包括必要的安全更改。

谷歌的帮助微乎其微,我清楚地记得在工作之前必须将几页的说明拼凑在一起。有人建议为 IIS 应用程序池启用性能计数器类别编辑的完整说明吗?

最佳答案

如果您不想在单独的进程中运行性能计数器代码,则可以通过提升权限来执行以下操作。

http://msdn.microsoft.com/en-us/library/bd20x32d(v=vs.71).aspx

上面的链接解释了 ASP.NET 应用程序中的性能计数器,以及 ASP.NET 在默认情况下如何没有创建自定义性能计数器的权限并且无法读取性能计数器。以下是文章的引用。

If you are using a PerformanceCounter component in an ASP.NET application, the default settings of the ASPNET user account restrict access to performance counters. The ASPNET user account, by default, can write to but not read from performance counters, and it cannot create new categories. You can use impersonation with the ASPNET account to allow creation of new categories. The impersonation identity must have sufficient privileges to create categories. If your application needs performance counters that can be specified before deployment, they can be created by the deployment project. For more information, see ASP.NET Web Application Security.

您可以模拟 asp 作为单独的帐户运行,您也可以授予该帐户权限。下面是 ASP.NET 模拟文章中的示例代码,当然您也可以加密该用户名和密码。本文介绍了如何对用户名和密码进行加密。

http://msdn.microsoft.com/en-us/library/aa719560(v=vs.71).aspx

关于c# - IIS7 应用程序内 WMI 自定义性能标记的权限问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12013771/

相关文章:

c# - 从 .NET 4.5.2 项目访问 appsettings.json

asp.net - TeamCity 构建任务以自动启动 ASP.NET 网站

asp.net - IIS7 集成与经典管道 - 使用更多 ASP.NET 线程?

c# - 如何将 WMI 集合显示到 WPF DataGrid

c# - 当父类也实现 IDisposable 时在子类上实现 IDisposable

c# - 在 Repeater 中渲染超链接控件

c# - 如何读取映射网络共享的 "friendly name"?

c# - AntivirusProduct c# 的 WMI 文档

c# - 在 Xamarin Forms 中等待 MessagingCenter

ASP.NET MVC3 - 你如何处理探测请求?