If you want to write to the Server's Event log from ASP.NET you'll first need to tweak some security settings. The first change is easy, however the second took me a while to find.

Step One:

Grant "Full Control" to the "IIS_WPG" group to the following registry key:

HKLM\SYSTEM\CurrentControlSet\Services\EventLog

Step Two:

One of the security restrictions added to IIS 6 under Windows Server 2003 was much tighter ACLs (Access Control Lists) on the event logs. This restricts what accounts can read and write to the logs (application, system & security). To overcome this you'll need to add the following value. Incase you're worried what security hole I'm opening up for you there's a breakdown of what it means at the end of the post.

(A;;0x0002;;;AU)

Add the above value to the end of the existing "CustomSD" value found at following path (pick relevant one):

HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application

HKLM\SYSTEM\CurrentControlSet\Services\EventLog\System

HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Security

So mine went from:

O:BAG:SYD:(D;;0xf0007;;;AN)(D;;0xf0007;;;BG)(A;;0xf0007;;;SY)(A;;0x7;;;BA)(A;;0x7;;;SO)(A;;0x3;;;IU)(A;;0x3;;;SU)(A;;0x3;;;S-1-5-3)

to: (scroll to all the way to the right to see the change in bold):

O:BAG:SYD:(D;;0xf0007;;;AN)(D;;0xf0007;;;BG)(A;;0xf0007;;;SY)(A;;0x7;;;BA)(A;;0x7;;;SO)(A;;0x3;;;IU)(A;;0x3;;;SU)(A;;0x3;;;S-1-5-3)(A;;0x0002;;;AU)

The value being added is written in Security Descriptor Definition Language (SDDL) and is as follows:

  • A = Access allowed.
  • ;; = token delimiter (don't know why there's two of them?)
  • 0x0002 = Permission to write log files.
  • ;;; = token delimiter (again - don't know why there's three of them?)
  • AU = Authenticated Users.

Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Thursday, March 06, 2008 11:44 AM | in .NET ASP.NET AJAX Microsoft Server 2003

Comments

Gravatar
# re: ASP.NET: Event Log in IIS6/Server 2003
on 4/7/2008 5:24 PM
To answer the questions about the semicolons.

The ACEs are specified in the following format:

ace_type;ace_flags;rights;object_guid;inherit_object_guid;account_sid

You can find the full documentation for security descriptor strings in the Microsoft Windows Platform SDK. The main articles are:

http://msdn2.microsoft.com/en-us/library/aa374928(VS.85).aspx

and

http://msdn2.microsoft.com/en-us/library/aa379570(VS.85).aspx

The beginning of the SD is harder to read because there isn't a separator between sections. In the above sections, the first section is O:BA and G:SY which means Owner:Built-in Administrators, Owner Group: Local System.

I wouldn't advise changing the rights to Authenticated Users because that leaves a large security hole. Instead, either add the particular user account that ASP.NET uses (the default Network Service account already has permissions, I believe) or create an isolated component with appropriate permissions, perhaps using a web service or .NET remoting.

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 6 and 5 and type the answer here: