SecurityException on EventLog.CreateEventSource

B

Bragadiru

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
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. Thanks.
 
S

Saurabh Nandu

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.

Regards
Akila
[MVP|MCAD]
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top