PRB: "Requested Registry Access Is Not Allowed" Error Message When ASP.NET Application Tries to Write New EventSource in the EventLog (329291)
The information in this article applies to:
- Microsoft ASP.NET (included with the .NET Framework 1.1)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual C# .NET (2003)
- Microsoft ASP.NET (included with the .NET Framework) 1.0
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2002)
- Microsoft Internet Information Services 5.0
- Microsoft Internet Information Services version 5.1
- Microsoft Internet Information Services version 6.0
This article was previously published under Q329291 IMPORTANT: This article contains information about modifying the registry.
Before you modify the registry, make sure to back it up and make sure that you
understand how to restore the registry if a problem occurs. For information
about how to back up, restore, and edit the registry, click the following
article number to view the article in the Microsoft Knowledge Base: 256986 Description of the Microsoft Windows Registry SYMPTOMS When you use ASP.NET to create a new event source in the event log, you may receive the following error message: System.Security.SecurityException: Requested registry access is
not allowed. CAUSE By default, the user token of the ASP.NET worker process is
ASPNET (or NetworkService
for applications that run on Internet Information Services [IIS] 6.0). The problem in the
"Symptoms" section occurs because your account does not have the correct user
rights to create an event source.RESOLUTIONWARNING: If you use Registry Editor incorrectly, you may cause serious
problems that may require you to reinstall your operating system. Microsoft
cannot guarantee that you can solve problems that result from using Registry
Editor incorrectly. Use Registry Editor at your own risk.
To resolve this problem, a user who has administrative
rights must create the event source before you run the ASP.NET Web Application.
To create an event source, use one of the following approaches. First ApproachCreate an event source under the Application event log in Registry Editor. To do this, follow these steps:
- Click Start, and then click
Run.
- In the Open text box, type
regedit.
- Locate the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application - Right-click the Application subkey, point
to New, and then click Key.
- Type TEST for the key
name.
- Close Registry Editor.
Second ApproachThe EventLogInstaller class in the System.Diagnostics namespace permits you to install
and configure an event log that your application reads from or writes to while
running. You can create an event source by using EventLogInstaller. To do this,
follow these steps:
- Use Microsoft Visual Basic .NET or Microsoft Visual C# .NET
to create a new Class Library named EventLogSourceInstaller.
By default, the Class1.vb file or the
Class1.cs file is created.
- In Solution Explorer, right-click
EventLogSourceInstaller, and then click Add
References.
- In the Add Reference dialog box,
double-click System.Configuration.Install.dll, and then click
OK.
- Rename the Class1.vb\Class1.cs to
MyEventLogInstaller.vb\MyEventLogInstaller.cs.
- Replace the existing code in MyEventLogInstaller.vb or
MyEventLogInstaller.cs with the following sample code:
Visual Basic
.NET SampleImports System.Diagnostics
Imports System.Configuration.Install
Imports System.ComponentModel
<RunInstaller(True)> _
Public Class MyEventLogInstaller
Inherits Installer
Private myEventLogInstaller As EventLogInstaller
Public Sub New()
' Create an instance of 'EventLogInstaller'.
myEventLogInstaller = New EventLogInstaller()
' Set the 'Source' of the event log, to be created.
myEventLogInstaller.Source = "TEST"
' Set the 'Log' that the source is created in.
myEventLogInstaller.Log = "Application"
' Add myEventLogInstaller to 'InstallerCollection'.
Installers.Add(myEventLogInstaller)
End Sub
End Class
Visual C# .NET Sampleusing System;
using System.Diagnostics;
using System.ComponentModel;
using System.Configuration.Install;
namespace EventLogSourceInstaller
{
[RunInstaller(true)]
public class MyEventLogInstaller : Installer
{
private EventLogInstaller myEventLogInstaller;
public MyEventLogInstaller()
{
//Create Instance of EventLogInstaller
myEventLogInstaller = new EventLogInstaller();
// Set the Source of Event Log, to be created.
myEventLogInstaller.Source = "TEST";
// Set the Log that source is created in
myEventLogInstaller.Log = "Application";
// Add myEventLogInstaller to the Installers Collection.
Installers.Add(myEventLogInstaller);
}
}
}
- On the Build menu, click Build
Solution to create
EventLogSourceInstaller.dll.
- Open the Visual Studio .NET Command Prompt.
- At the command prompt, change to the folder where
EventLogSourceInstaller.dll is located.
- Run the following command to create the EventSource:
InstallUtil EventLogSourceInstaller.dll
REFERENCESFor more information, visit the following Microsoft Web
sites:
Modification Type: | Minor | Last Reviewed: | 7/8/2005 |
---|
Keywords: | kberrmsg kbWebForms kbSecurity kbprb KB329291 kbAudDeveloper |
---|
|