如果 XBAP 在调试器外部运行,ExceptionPolicy.HandleException 不会安装用于登录注册表的事件源

发布于 2024-08-31 10:29:29 字数 476 浏览 3 评论 0原文

我正在使用(Microsoft Enterprise Library 的)日志记录应用程序块来记录事件查看器中发生在我的 WPF XBAP 应用程序中的异常。

如果我在 Visual Studio 的调试器中运行 XBAP,则会在注册表中自动创建应用程序的事件源条目:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\MyApp

这发生在调用 ExceptionPolicy.HandleException() 时。

但是,如果我直接从文件系统或其发布位置在 IDE 外部运行 XBAP,则不会添加注册表项。因此,不会发生任何日志记录。

我只能假设这是运行 XBAP 应用程序的安全问题,并且它们无权写入注册表。这是我的项目中的设置吗?知道为什么会发生这种情况吗?

非常感谢任何帮助。

I am using the Logging Application Block (of Microsoft Enterprise Library) to log exceptions in the Event Viewer that occur in my WPF XBAP application.

If I run the XBAP in the debugger from Visual Studio, an Event Source entry for my application is automatically created in the Registry at:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\MyApp

This occurs at the point ExceptionPolicy.HandleException() is called.

However, if I run the XBAP outside of the IDE directly from the file system or from its published location, the Registry entry isn't added. Therefore, no logging takes place.

I can only assume this is a security issue with running XBAP applications and they do not have access to write to the Registry. Is this a setting within my project? Any idea on why this might be happening?

Any help much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

只有一腔孤勇 2024-09-07 10:29:29

你说得对,这是一个权限问题。

如果您尝试记录到事件日志,但事件源不存在,运行时将尝试为事件源创建注册表项。如果您没有权限,则会出现 System.Security.SecurityException,并显示消息“不允许请求的注册表访问”。被抛出。企业库捕获此异常并尝试记录它无法记录该消息。如果这也失败了,那么异常就会被吞掉。

该应用程序正在部分信任沙箱中运行,因此不会有创建注册表项的权限。您可以尝试将应用程序配置为作为 完全信任应用程序。虽然这篇文章 说这可能仍然存在问题。

从 ASP.NET 登录时也会经常出现此问题,通常的解决方案是在部署过程中创建所需的注册表项。对于 WPF,这感觉有点不对劲,但是是否可以创建一个安装注册表项的 Windows Installer (.msi)?然后应用程序不需要写入注册表(尽管它仍然需要从注册表中读取,因此希望不存在权限问题!)。

更新回应评论

上面的网址

是的,这是我们的设计缺陷
托管过程。您获得“充分信任”
从 CLR 的角度来看,但不是
NT 安全条款。我们会尽力
将来解决这个问题
发布。

我不确定问题是否已解决,但可能就是您所看到的。

You are right about it being a permission problem.

If you try to log to the event log and the event source does not exist the runtime will attempt to create a registry entry for the event source. If you don't have permission then a System.Security.SecurityException with a message of "Requested registry access is not allowed." is thrown. Enterprise Library catches this exception and attempts to log saying that it couldn't log the message. If that also fails then the exception is swallowed.

The application is running in a partial trust sandbox so wouldn't have permission to create registry keys. You could try configuring the application to run as a Full Trust Application. Although this post says that there may still be a problem with that.

This issue also arises frequently when logging from ASP.NET and the usual solution is to create the required registry keys during the deployment process. For WPF this feels a bit wrong, but is it possible to create a Windows Installer (.msi) that installs the registry keys? Then the application wouldn't need to write to the registry (although it would still need to read from the registry so hopefully there is no permission problem with that!).

UPDATE in response to comment

As mentioned in the URL above:

Yes, this is a design flaw in our
hosting process. You get "full trust"
from CLR point of view, but not in
terms of NT security. We'll try to
address this issue in a future
release.

I'm not sure if the issue has been resolved or not but it may be what you are seeing.

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