无法在 Azure Web 角色中创建自定义性能计数器
尝试按照这篇 MSDN 文章中的说明创建自定义性能计数器时,我仍然遇到安全异常。
我使用的代码与那篇文章中的代码相同,只是我创建了不同的计数器。
我知道我可以尝试在启动任务中创建它,但现在我想在角色内部执行它..它应该可以工作:/
例外:
[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
我的 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 身份运行,当我将角色更改为“提升”时,我希望它在不同的主体下运行 - 手动设置具有权限的自定义主体可以解决此问题,但它将被覆盖一次角色重新配置自身或者如果我部署升级 - 无论如何,这不是真正的解决方案,而是黑客:/ [沮丧]
When trying to create custom performance counters as explained in this MSDN article, I still get a security exception.
The code I am using is the same as in that article, only I am creating a different counters.
I understand that I can try to create it in a start-up task, but for now I want to do it inside the role.. it should work :/
The exception:
[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
The beginning of 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" />
When I RDP into the role, I can see that the application pool is still running with the NetworkService identity, was expecting it to run under a different principal as I changed the role to be 'elevated' - manually setting up a custom principal with permissions solves this, but it will be over-ridden once the role reconfigure itself or if I deploy an upgrade - in any case, this is not really a solution but a hack :/ [frustrated]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于完整 IIS 的 Web 角色,您在 Runtime 元素中指定的特殊权限将应用于 RoleEntoryPoint。我认为有必要通过内部 RoleEntryPoint(通常是 WebRole.cs)OnStart 方法注册自定义性能计数器。
In the case of Web Role of Full IIS, the special privilege which you appointed in Runtime element is applied to RoleEntoryPoint. I think that it is necessary to register a custom performance counter by inner RoleEntryPoint (usually WebRole.cs) OnStart method.