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

发布于 2025-01-02 22:53:11 字数 1545 浏览 0 评论 0原文

尝试按照这篇 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欢烬 2025-01-09 22:53:11

对于完整 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文