Re: Event Log Trust Level?

From: Joe Kaplan (ilearnedthisthehardway@noway.com)
Date: 02/06/03


From: "Joe Kaplan" <ilearnedthisthehardway@noway.com>
Date: Thu, 6 Feb 2003 08:55:44 -0600


This is a common problem in ASP.NET apps because the ASPNET account that the
aspnet_wp.exe process runs under by default doesn't have the rights to
create event sources or even call SourceExists. It can only write to the
event log.

What I do in this case is install the event log as part of an installer
package and then just use write to the event log from the app. The obvious
disadvantage is your deployment becomes more complicated. You could also
change the permissions for the ASPNET account or choose a different
processModel with higher permissions, but the installer is the better way to
go.

Cheers,

Joe K.

"Steve Hindmarsh" <s.hindmarsh@ukonline.co.uk> wrote in message
news:067501c2cdcf$411e8a00$d5f82ecf@TK2MSFTNGXA12...
> 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:
>
> ' 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
> allowed.]
> Microsoft.Win32.RegistryKey.OpenSubKey(String name,
> Boolean writable) +473
> System.Diagnostics.EventLog.CreateEventSource(String
> source, String logName, String machineName, Boolean
> useMutex)
> System.Diagnostics.EventLog.CreateEventSource(String
> source, String logName, String machineName)
> System.Diagnostics.EventLog.CreateEventSource(String
> source, String logName)
> WebApplication1.WebForm1.Button1_Click(Object sender,
> EventArgs e) in \\next-gen-server\wwwroot$\WebApplication1
> \WebForm1.aspx.vb:29
> System.Web.UI.WebControls.Button.OnClick(EventArgs e)
>
> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEv
> entHandler.RaisePostBackEvent(String eventArgument)
> System.Web.UI.Page.RaisePostBackEvent
> (IPostBackEventHandler sourceControl, String
> eventArgument)
> System.Web.UI.Page.RaisePostBackEvent
> (NameValueCollection postData)
> System.Web.UI.Page.ProcessRequestMain()
> System.Web.UI.Page.ProcessRequest()
> System.Web.UI.Page.ProcessRequest(HttpContext context)
> System.Web.CallHandlerExecutionStep.Execute()
> System.Web.HttpApplication.ExecuteStep(IExecutionStep
> step, Boolean& completedSynchronously)
>
>
> Any help appreciated as I'm leaving this establishment
> tommorrow.
>
> Steve Hindmarsh
> App developer
>
>
>