Search
Close this search box.

‘System.Security.SecurityException: Requested registry access is not allowed.’ when writing to event log

I got this error when I try to create an eventlog source and when I try to write to the new event log (after resorting to manually creating the event log source) with my ASP.NET application.

See the end of this post for the full error message and stack trace.

This seems to be a very commom problem – and not consistent either.  My guess is that it’s due to the tightening of security recently, ie XP SP2.  Use of the Network Service account (on win2k3) or AD accounts can help.

To resolve you need to give the ASP.NET user permission to read from the event log registry entries.  And here’s how:

  1. Select Start – Run, then enter: regedt32
  2. Navigate/expand to the following key:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Security
  3. Right click on this entry and select Permissions
  4. Add the ASPNET user
  5. Give it Read permission

Bingo! – your app should now work.

HTH

Tim

Full error message:

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.]

Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +473

System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly) +296

System.Diagnostics.EventLog.SourceExists(String source, String machineName) +79

System.Diagnostics.EventLog.SourceExists(String source) +11

DrKW.Directory.DebugLog.LogEntry(String logMessage, EventLogEntryType type) +16

DrKW.Directory.DebugLog.Error(String logMessage) +18

DrKW.Directory.HttpModule.ConfigSectionHandler.Create(Object parent, Object configContext, XmlNode configNode) in C:\.NETLocalProjects\DrKWDirectory\Directory.HttpModule\Configuration\ConfigSectionHandler.cs:72
System.Web.Configuration.HttpConfigurationRecord.EvaluateRecursive(IConfigurationSectionHandler factory, Object config, String[] keys, Int32 iKey, XmlUtil xml) +3
This article is part of the GWB Archives. Original Author: Tim Huffam

Related Posts