简体   繁体   English

在 IIS 8 上托管的 ASP.NET Web 应用程序上读取系统事件日志条目时访问被拒绝

[英]Access denied when reading system event log entries on ASP.NET web application hosted on IIS 8

I have developed a quite simple ASP.NET web application that reads the system event logs entries.我开发了一个非常简单的ASP.NET Web 应用程序,它可以读取系统事件日志条目。

When I am debugging or running it from VS 2017 (hosted in IIS Express ) I am able to read the log entries without any issue.当我从 VS 2017 (托管在IIS Express 中调试或运行它时,我能够毫无问题地读取日志条目。

Once I deploy/publish this asp.net web app on IIS 8 and try to read the system event log entries it doesn't work.一旦我在IIS 8上部署/发布这个 asp.net web 应用程序并尝试读取系统事件日志条目,它就不起作用。 If I check the event viewer I get something like this (translated from Spanish) :如果我检查事件查看器,我会得到这样的信息(从西班牙语翻译):

System.InvalidOperationException: Unable to open the Application record on the computer Windows has not provided an error code. System.InvalidOperationException:无法打开计算机上的应用程序记录 Windows 未提供错误代码。 ---> System.ComponentModel.Win32Exception: Access Denied" ---> System.ComponentModel.Win32Exception:访问被拒绝”

I have read other questions but are related to writing in the event log.我已阅读其他问题,但与写入事件日志有关。 I'm just interested in being able to read system event log entries.我只是对能够读取系统事件日志条目感兴趣。 I guess it has something to do with permissions but I don't know which permissions I would have to set and to which user.我想这与权限有关,但我不知道我必须设置哪些权限以及设置给哪个用户。

Here there are some parts of my code:这里有我的代码的一些部分:

System.Diagnostics.EventLog  eventLog = new EventLog(LogName, machineName);
...
EventLogEntryCollection entries = eventLog.Entries; //This is where I get the Acces denied Exception.

Answer (workaround)答案(解决方法)

It may be not the proper way to solve it (for security issues), but as it is for the moment an internal application, I have made it work like this.这可能不是解决它的正确方法(对于安全问题),但由于它目前是一个内部应用程序,因此我使它像这样工作。 That is, read the log Events from several remote machines through the use of impersonate on my web.config file即通过在我的web.config文件中使用impersonate从多台远程机器读取日志事件

<system.web>   
   <identity impersonate="true" userName="SomeDomainUserWithRigtsToread" password="itsPwd"/>

Note : It may be not the proper way to solve it (for security issues ), but as it is for the moment an internal application, I have made it work, that is, read the log Events from several remote machines through the use of impersonate on my web.config file注意:这可能不是解决它的正确方法(出于安全问题),但由于它目前是一个内部应用程序,我已经使它工作,即通过使用从几台远程机器读取日志事件模拟我的 web.config 文件

<system.web>   
   <identity impersonate="true" userName="SomeDomainUserWithRigtsToread" password="itsPwd"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM