Official solution to the problem of ASP.net write registry permissions

Source: Internet
Author: User
Tags log net command knowledge base visual studio
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:
    1. Click Start, and then click Run.
    2. In the Open text box, type regedit.
    3. Locate the following registry subkey:
      Hkey_local_machine\system\currentcontrolset\services\eventlog\application
    4. Right-click the application subkey, point to New, and then click Key.
    5. Type TEST for the key name.
    6. 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:
  1. 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.
  2. In Solution Explorer, right-click EventLogSourceInstaller, and then click Add References.
  3. In the Add Reference dialog box, double-click System.Configuration.Install.dll, and then click ok .
  4. Rename the Class1.vb\class1.cs to Myeventloginstaller.vb\myeventloginstaller.cs.
  5. Replace the existing code in Myeventloginstaller.vb or MyEventLogInstaller.cs with the following sample code:

    Visual Basic. NET Sample
    Imports 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);         }    }}
  6. On the "Build" menu, click Build Solution to create EventLogSourceInstaller.dll.
  7. Open the Visual Studio. NET Command Prompt.
  8. At the command prompt, change to the folder where EventLogSourceInstaller.dll is located.
  9. Run the following command to create the EventSource:
    InstallUtil EventLogSourceInstaller.dll
More Information

Steps to reproduce the Behavior

  1. Use visual Basic. NET or Visual C #. NET to create a new asp.net Web application. By default, WebForm1.aspx the file is created.
  2. 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" >
  3. On the Debug menu, click the " Start to view" WebForm1.aspx page in the browser.
  4. Type some text in TextBox, and then click Write to Event log.
  5. The error message which is discussed in the "Symptoms" section of this article appears.
  6. 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")
  7. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.