“无法打开源日志” - Windows 7 - .NET Web 服务 - 事件日志
我有一个 .NET Web 服务正在尝试记录到 Windows 事件日志。但是,当我尝试向此 Web 服务中的 Web 方法发送 SOAP 请求时,我在 SOAP 响应中收到以下错误:
System.InvalidOperationException:无法打开源“MySource”的日志。您可能没有写入权限。 ---> System.ComponentModel.Win32Exception:访问被拒绝
我已尝试在谷歌上搜索解决方案。 这个描述了编辑Windows 7 64位中不存在的注册表项; 此 Microsoft 页面也是如此。 此问题相关,但唯一的答案它谈到了一个“Source”键,该键似乎不在 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\eventlog\MySource 中的任何位置。如果我需要添加 Source 键,它的值需要是多少?我在 Web 服务的 Web.config 中使用模拟 (
)。 这个问题 也相关,但没有答案。 此问题相关但它的答案似乎与 Windows 7 中的注册表设置无关。
我有
和
在我的 Web.config 中设置。但是,即使我删除
,我仍然收到“无法打开源日志”错误。
I have a .NET web service that is trying to log to the Windows Event Log. However, when I try to send a SOAP request to a web method in this web service, I get back this error in the SOAP response:
System.InvalidOperationException: Cannot open log for source 'MySource'. You may not have write access. ---> System.ComponentModel.Win32Exception: Access is denied
I've tried Googling around for a solution. This one describes editing a registry key that does not exist for me in Windows 7 64-bit; same for this Microsoft page. This question is related but the only answer to it talks about a 'Source' key that does not seem to be anywhere in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\eventlog\MySource. If I need to add a Source key, what does its value need to be? I am using impersonation in my web service's Web.config (<identity impersonate="true" />
). This question is related as well but has no answers. This question is related but again its answer doesn't seem to pertain to the registry setup in Windows 7.
I have both <authentication mode="Windows" />
and <identity impersonate="true" />
set in my Web.config. However, even when I remove <authentication mode="Windows" />
, I still get the "Cannot open log for source" error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 Windows 7 64 位中的经典 ASP Web 应用程序中遇到了完全相同的问题。我最终发现,通过将该网站的应用程序池更改为“启用 32 位应用程序”(右键单击应用程序池,高级设置),问题就消失了。
I was having the exact same problem in Windows 7 64 bit for my classic ASP web application. I eventually found that by changing the application pool for that website to "Enable 32-bit Applications" (right-click application pool, advanced settings) the problem disappeared.
参见这里:
注意
要在 Windows Vista、Windows XP Professional 或 Windows Server 2003 中创建事件源,您必须具有管理权限。
此要求的原因是必须搜索所有事件日志(包括安全日志)以确定事件源是否唯一。在Windows Vista中,用户没有访问安全日志的权限;因此,会抛出 SecurityException。
在 Windows Vista 中,用户帐户控制 (UAC) 确定用户的权限。如果您是内置管理员组的成员,则会为您分配两个运行时访问令牌:标准用户访问令牌和管理员访问令牌。默认情况下,您具有标准用户角色。要执行访问安全日志的代码,您必须首先将权限从标准用户提升到管理员。您可以在启动应用程序时执行此操作,方法是右键单击应用程序图标并指示您要以管理员身份运行。
解决方案:您应该使用安装程序设置日志源或以管理员身份运行的实用程序。如果您不确定,只需使用您在 Web 服务中使用的相同代码来记录“安装实用程序已完成”消息。
(您不应该以管理员权限运行 Web 服务)
希望有所帮助!
See here:
Note
To create an event source in Windows Vista, Windows XP Professional, or Windows Server 2003, you must have administrative privileges.
The reason for this requirement is that all event logs, including security, must be searched to determine whether the event source is unique. In Windows Vista, users do not have permission to access the security log; therefore, a SecurityException is thrown.
In Windows Vista, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To execute the code that accesses the security log, you must first elevate your privileges from standard user to administrator. You can do this when you start an application by right-clicking the application icon and indicating that you want to run as an administrator.
Solution: You should set up the log source using an installer or utility that runs as Administrator. If you are unsure, just use the same code that you use in your Web Service to log a 'Installation Utility Completed' message.
(You should not run the web service with Administrator privileges)
Hope that helps!