views:

84

answers:

1

Hi all,

I'm using NLog in my ASP.NET application hosted on IIS and Windows server 2003. When I run the code on my develop machine, everything is Okay. But when I deployed the code to the server. The initialization of NLog target will cause an security exception:

Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Requested registry access is not allowed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[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
NLog.Targets.EventLogTarget.CreateEventSourceIfNeeded() +637 NLog.Targets.EventLogTarget.InitializeTarget() +40 NLog.Targets.Target.Initialize() +264 NLog.Config.LoggingConfiguration.InitializeAll() +233

Does anyone when what should I do in order to give the application proper permission? Thanks!

A: 

Okay, I got it. Network Service account does not have permission to read/write the event log. That's why the exception thrown.

Roy