【发布时间】:2010-12-09 06:32:52
【问题描述】:
我创建了一个包含一些业务逻辑的库,其中包括写入System.Diagnostics.EventLog 实例。该库通常是从 Windows 服务应用程序调用的,但现在我正尝试从我的 ASP.NET MVC 应用程序调用这些相同的库函数。
我在我的控制器中尝试了这段代码来创建我传递给需要写入日志的方法的 EventLog 实例。
Dim log = New EventLog("Application", My.Computer.Name, "MyMVCApp")
当库方法中的代码尝试写入日志时,会产生以下错误:
[SecurityException: Requested registry access is not allowed.]
System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) +51
Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +7462217
System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) +366
System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName) +194
System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) +205
System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type) +14
我的 Web 应用程序在运行 IIS 6 的 Windows Server 2003 上作为网络服务用户运行。我需要做些什么才能让网络服务用户访问注册表吗?
有没有更好的方法来创建用于 ASP.NET MVC 应用程序的 EventLog 实例?框架是否已经创建了一个我只需要引用的框架?
【问题讨论】:
标签: asp.net-mvc iis-6 event-log securityexception