Asp.net| Solution | problem | Registration FORM
PRB: "Requested Registry Access isn't allowed" Error message when asp.net application tries to Write New EventSource in t He EventLog
The information in this article applies to:
- Microsoft asp.net (included with the. NET Framework) 1.0
- Microsoft Visual Basic. NET (2002)
- Microsoft Visual C #. NET (2002)
This is article was previously published under Q329291
IMPORTANT: This article contains information about modifying the registry. Before you are modify the registry, make sure to-back it's up and make sure this you understand I to restore the registry if a Problem occurs. For information about you, restore, and edit the registry, click the following article number to view the Artic Le in the Microsoft knowledge Base:
256986 Description of the Microsoft Windows Registry
SymptomsWhen you create a new event source in the event log by using ASP.net, the ' may receive ' following error message:
System.Security.SecurityException:Requested registry access is not allowed.
causeBy default, the user token to the ASP.net worker process is ASPNET. The problem in the ' Symptoms ' section occurs because your account does not have the ' correct user rights to create ' event Source.
resolution
WARNING: If You use Registry Editor incorrectly, or may cause serious problems this may require your to reinstall your System. Microsoft cannot guarantee that can solve problems this result from using the Registry Editor. 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 a event source, use one of the following approaches.
The approach
Create an event source under the
ApplicationEvent Log in Registry Editor. To doing 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 approach
The
EventLogInstallerClass in the System.Diagnostics namespace permits you to install and configure a event log that your application reads FR Om or writes to while running. You can create a event source by using EventLogInstaller. To doing this, follow these steps:
- Use Microsoft Visual Basic. NET or Microsoft Visual C #. NET to create a new Class Library named Eventlogsourceins Taller. 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.diagnosticsimports System.Configuration.InstallImports 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 ' ' Source ' Event log, to be created. myeventloginstaller.source = "TEST" ' Set the ' Log ' that ' the source is created in. & Nbsp; myeventloginstaller.log = "Application" ' Add myEventLogInstaller to ' installercollection ' . Installers.add (myEventLogInstaller) end Sub End Class
Visual C #. NET Sample Using 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. & Nbsp; myeventloginstaller.source = "TEST"; //Set The Log that the 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
More Information
Steps to reproduce the Behavior
- Use visual Basic. NET or Visual C #. NET to create a new asp.net Web application. By default, WebForm1.aspx the file is created.
- In the HTML view ofWebForm1.aspx, replace the existing code with the following sample code:
Visual Basic. NET Sample<%@ Page language= "vb" autoeventwireup= "true"%><%@ Import namespace= "System.Diagnostics"%><! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
- On the Debug menu, click the " Start to view" WebForm1.aspx page in the browser.
- Type some text in TextBox, and then click Write to Event log.
- The error message which is discussed in the "Symptoms" section of this article appears.
- To resolve this problem, create ' Event Source as discussed in the ' Resolution ' section, and comment the following code I N WebForm1.aspx :
EventLog.CreateEventSource (EV. Source, "Application")
- Repeat steps 3 and 4.
REFERENCESFor more information, visit the following Microsoft Web sites:
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkWalkthroughCreatingEventLogInstallers.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/ Frlrfsystemdiagnosticseventlogclasstopic.asplast reviewed:1/3/2003keywords:kbprb kberrmsg kbWebForms kbSecurity KB329291 kbAudDeveloper Kbauditpro