Re: ASPNET Event Log Access

From: Joe Kaplan \(MVP - ADSI\) (joseph.e.kaplan_at_removethis.accenture.com)
Date: 08/27/03


Date: Wed, 27 Aug 2003 12:22:00 -0500


You actually can write to the event log with the default permissions that
ASPNET, you just can't create the event source as you have discovered. In
your case, a good way to do this might be to package up your ASP.NET
application in an installer package and include an EventLogInstaller. If
that is set to run as a custom action, you event log will get created during
install. You don't need to hack up the registry by hand. There are samples
in the help show how to do this.

You could also elevate the privileges of the ASPNET account to give it the
necessary rights to the event log, but this remember that elevating
privileges is generally a bad idea. The account is very low privileged for
a reason, even though there are many inconveniences that come with this.

HTH,

Joe K.

"Charles Leonard" <elmsdn13@hotmail.com> wrote in message
news:019501c36cad$e1f88b10$a101280a@phx.gbl...
> From what I have read, finding a convenient way to access
> and write to the Application Event Log from within a Web
> Service application is a common, frustrating problem. I'm
> not quite sure why this was made so difficult for
> something that seems so harmless, necessary and is the
> common logging standard.
>
> Here's what I have tried:
>
> *Add the ASPNET user to the Application Event Log
> security with "Full Control" in the Registry (using
> regedt32).
>
> The above suggestion works only if the Application Log
> source (i.e. the name of the application) preexists in the
> Registry. Below is an excerpt of the code I am using to
> access/write to the Application Event Log within my Web
> Service:
>
> objEventLog = new System.Diagnostics.EventLog();
> if (!System.Diagnostics.EventLog.SourceExists
> (strProgName))
>
> System.Diagnostics.EventLog.CreateEventSource(
> "MyProg", "Application");
> objEventLog.Source = strProgName;
> objEventLog.WriteEntry(strData,
> System.Diagnostics.EventLogEntryType.Error);
>
> The above code works great in a non-web application. But,
> it will not work within my Web Service unless the "MyProg"
> source pre-exists in the Registry (along with the proper
> ASPNET permissions established). Of course I can
> accomplish the source creation by running the code outside
> the Web Service in the non-web application to create my
> log source.
>
> However, this circumstance is not ideal when you consider
> deployment into a production environment. That leaves two
> things I can do in the installation process: 1) Run the
> non-web application during the installation process to
> create the log source 2) deliver registry settings to
> create the log source within the Application Log.
>
> My complaint is that this is a lot of trouble to do
> something that seems innocuous. Logging to the
> Application Event log is a very useful tool and something
> administrators have come to expect from Windows programs.
> Furthermore, since I have told the Registry that ASPNET
> has "Full Control" (write access, etc.) one would think
> that should be enough to let the above code work without
> having to do anything extra (i.e. I should not have to
> manually figure out how I can create a log source-the
> above code should just work).
>
> Does anyone know of any other tricks to allow the above
> code to work within a Web Service that is simple and does
> not involve impersonation? Also, does anyone know if
> Microsoft has any plans to address this issue in a future
> version of Visual Studio .NET?
>
> Thanks.
>
> --Charles Leonard
>
>
>



Relevant Pages

  • ASP.NET Permission Writing to NT Event Log
    ... rights an account needs to be able to both create and write to the NT ... Event Log from ASP.NET in windows 2000 and 2003 server? ... to see a list of files and registry keys are required for the aspnet ... The full control registry permissions and subkeys as well as the create ...
    (microsoft.public.dotnet.general)
  • Re: ASPNET cant write in event log on win XP
    ... I also put ASPNET in ... >> Changing file and folder permissions isn't going to help anything. ... >> to change permissions for the Event Log. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: EventLog access through ASP.Net app.
    ... the ASPNET account has rights to write to the event log. ... event source exists, so calling that method might not work either. ... I encountered the initial security exceptionwhen ...
    (microsoft.public.dotnet.security)
  • Re: Security- access to Event Viewer- SOS
    ... Actually, if an web application must create a new event log category, the ... which the ASPNET account cannot do (If we set ... I impersonate in the code to the local administrator. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Excel function not working in ADOMD
    ... launch a DCOM Server using DefaultLaunchPermssion. ... ASPNET in the Event Log. ...
    (microsoft.public.sqlserver.olap)