lapucca
asked on
Got security exception error. What permission is needed to write/create windows event log?
Hi, I'm using vs2012.
i'm getting the following error when my code try to create new event log and event source. I then added impersonation code, stepping through it is impersonating successfully. the impersonated account is added to the local Administrator group of the server but still I would get security error. What other permission still needed? Thank you.
Both code below would give security error
//if ((!EventLog.Exists(sLog)) || (!EventLog.SourceExists(sS ource)))
// EventLog.CreateEventSource (sSource, sLog);
if (!EventLog.SourceExists(sS ource))
EventLog.CreateEventSource (sSource, sLog);
ecurity 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.SecurityEx ception: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
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: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.]
System.Diagnostics.EventLo g.FindSour ceRegistra tion(Strin g source, String machineName, Boolean readOnly, Boolean wantToCreate) +806
System.Diagnostics.EventLo g.SourceEx ists(Strin g source, String machineName, Boolean wantToCreate) +315
System.Diagnostics.EventLo g.SourceEx ists(Strin g source) +22
XXXXXXXXXXXXXXXXXXXXXXX.Er rLog.LogIt (String msg) +143
XXXXXXXXXXXXXXXXXXXXXXX._D efault.Get UsersToSes sion() +2444
System.Web.UI.Control.Load Recursive( ) +71
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +12347355
System.Web.UI.Page.Process Request(Bo olean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +12346873
System.Web.UI.Page.Process Request() +119
System.Web.UI.Page.Process Request(Ht tpContext context) +99
System.Web.CallHandlerExec utionStep. System.Web .HttpAppli cation.IEx ecutionSte p.Execute( ) +913
System.Web.HttpApplication .ExecuteSt ep(IExecut ionStep step, Boolean& completedSynchronously) +165
i'm getting the following error when my code try to create new event log and event source. I then added impersonation code, stepping through it is impersonating successfully. the impersonated account is added to the local Administrator group of the server but still I would get security error. What other permission still needed? Thank you.
Both code below would give security error
//if ((!EventLog.Exists(sLog)) || (!EventLog.SourceExists(sS
// EventLog.CreateEventSource
if (!EventLog.SourceExists(sS
EventLog.CreateEventSource
ecurity 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.SecurityEx
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: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.]
System.Diagnostics.EventLo
System.Diagnostics.EventLo
System.Diagnostics.EventLo
XXXXXXXXXXXXXXXXXXXXXXX.Er
XXXXXXXXXXXXXXXXXXXXXXX._D
System.Web.UI.Control.Load
System.Web.UI.Page.Process
System.Web.UI.Page.Process
System.Web.UI.Page.Process
System.Web.UI.Page.Process
System.Web.CallHandlerExec
System.Web.HttpApplication
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
before I write to the event log. The user impersonate is added to the local server's Administrator's group. Wouldn't that be enough? I know it's not because it's getting security error but that doesn't make sense if I'm impersonating a user account that is part of Administrators group
ImpersonateManager.Imperso
var curUser = WindowsIdentity.GetCurrent
sSource = "XXXXXXXXX";
sLog = "XXXXXXXXX";
sEvent = "XXXXXXXXXXXX Exception Error";
//if ((!EventLog.Exists(sLog)) || (!EventLog.SourceExists(sS
// EventLog.CreateEventSource
if (!EventLog.SourceExists(sS
EventLog.CreateEventSource
EventLog.WriteEntry(sSourc
ImpersonateManager.StopImp