SecurityException on EventLog.CreateEventSource

Discussion in 'ASP .Net Web Services' started by Bragadiru, Nov 24, 2003.

  1. Bragadiru

    Bragadiru Guest

    Hi All,

    Can anybody tell me how to write to the application event log with a new
    source. I'm running the .Net example code
    but can't get it to work unless the source is set to application. This is
    driving me nuts. I have created a new WebApplication1 so as everything is
    set to defaults and then I tried using the .Net Eventlog example source:
    I need this eventlog. Do you know a workaround ?

    ' Create the source, if it does not already exist.
    If Not EventLog.SourceExists("MySource") Then
    EventLog.CreateEventSource("MySource", "MyLog")
    End If

    ' Create an EventLog instance and assign its source.
    Dim myLog As New EventLog()
    myLog.Source = "MySource"

    ' Write an informational entry to the event log.
    myLog.WriteEntry("Writing to event log.")

    but it comes back with this 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
    Microsoft.Win32.RegistryKey.OpenSubKey(String name,
    Boolean writable) +473
    source, String logName, String machineName, Boolean
    source, String logName, String machineName)
    source, String logName)
    WebApplication1.WebForm1.Button1_Click(Object sender,
    EventArgs e) in \\next-gen-server\wwwroot$\WebApplication1
    System.Web.UI.WebControls.Button.OnClick(EventArgs e)

    entHandler.RaisePostBackEvent(String eventArgument)
    (IPostBackEventHandler sourceControl, String
    (NameValueCollection postData)
    System.Web.UI.Page.ProcessRequest(HttpContext context)
    step, Boolean& completedSynchronously)

    Any help appreciated. Thanks.
    Bragadiru, Nov 24, 2003
    1. Advertisements

  2. Hi,

    In your Web.Config,
    set the following
    <identity impersonate=true/>. You can also specify a specific user account
    ot be impersonated.

    The other option is
    in machine.config, Set the User attribute of <processModel> to "SYSTEM".
    Restart the machine.

    Saurabh Nandu, Nov 29, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.