无法在Azure Web角色中创建自定义性能计数器

无法在Azure Web角色中创建自定义性能计数器,azure,performancecounter,azure-web-roles,Azure,Performancecounter,Azure Web Roles,在尝试创建自定义性能计数器时(如前所述),我仍然会遇到一个安全异常 我使用的代码与那篇文章中的代码相同,只是我创建了一个不同的计数器 我知道我可以尝试在启动任务中创建它,但现在我想在角色内部创建它。。它应该在以下方面发挥作用:/ 例外情况: [SecurityException: Requested registry access is not allowed.] Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean wri

在尝试创建自定义性能计数器时(如前所述),我仍然会遇到一个安全异常

我使用的代码与那篇文章中的代码相同,只是我创建了一个不同的计数器

我知道我可以尝试在启动任务中创建它,但现在我想在角色内部创建它。。它应该在以下方面发挥作用:/

例外情况:

[SecurityException: Requested registry access is not allowed.]
   Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +12746267
   System.Diagnostics.PerformanceCounterLib.CreateRegistryEntry(String categoryName, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection creationData, Boolean& iniRegistered) +170
   System.Diagnostics.PerformanceCounterLib.RegisterCategory(String categoryName, PerformanceCounterCategoryType categoryType, String categoryHelp, CounterCreationDataCollection creationData) +49
   System.Diagnostics.PerformanceCounterCategory.Create(String categoryName, String categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) +558
my ServiceDefinition.csdef的开头:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="Jonathan.Cloud" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="WebDriver" vmsize="Small" enableNativeCodeExecution="true">
    <Runtime executionContext="elevated" />


当我将RDP添加到角色中时,我可以看到应用程序池仍在使用NetworkService标识运行,当我将角色更改为“提升”时,我希望它在其他主体下运行—手动设置具有权限的自定义主体解决了这一问题,但是,一旦角色重新配置自身,或者如果我部署了升级,它将被过度利用——无论如何,这不是一个真正的解决方案,而是一个黑客:/[沮丧]

对于完全IIS的Web角色,您在运行时元素中指定的特权将应用于RoleEntoryPoint。我认为有必要通过内部RoleEntryPoint(通常是WebRole.cs)OnStart方法注册自定义性能计数器。

您是否尝试过使用Microsoft Azure Powershell cmdlet而不是自己包装管理API?下面是David Aiken关于如何使用PowerShell远程配置诊断信息的文章。你说得对,这很有效!:)我将初始化计数器的代码移到了RoleEntryPoint的OnStart(),删除了现有部署以确保我开始清理,并发布了它-works并注册了计数器。还请记住在.csdef文件中包含配置(如示例中所示)