Article ID: 2028427 - View products that this article applies to.
You have an ASP.NET or legacy ASP application running on Internet Information Services (IIS) 6.0 or later. Your application logs events to the Windows Event Logs. Writing to the event logs fails with an error message similar to the following:
System.Security.SecurityException: Requested registry access is not allowed.
System.ComponentModel.Win32Exception: Access is denied
InvalidOperationException : Cannot open log for source 'Application'. You may not have write access.
Legacy ASP application
This problem occurs because by default the user token of the application does not have the required user rights to write to the windows event logs due to limited security access.
Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/322756/)How to back up and restore the registry in Windows
To provide the required permissions to the thread identity, modify the security of the event log through the below registry keys on the server machine. You should select the event log that your application is writing to:
The CustomSD registry value is of type REG_SZ and contains a security descriptor in Security Descriptor Definition Language (SDDL) syntax. For more information on SDDL Syntax, please see the links in the More Information section below.
To construct a SDDL string, note that there are three distinct rights that pertain to event logs: Read, Write, and Clear. These rights correspond to the following bits in the access rights field of the ACE string:
2 = Write
4 = Clear
Important: You can configure the security log in the same way. However, you can change only Read and Clear access permissions. Write access to the security log is reserved only for the Windows Local Security Authority (LSA).
The following is a sample SDDL that shows the default SDDL string for the Application log. Access rights (in hexadecimal) are bold-faced:
O:BA Object owner is Built-in Admin (BA).
G:SY Primary group is System (SY).
D: This is a DACL, rather than an audit entry or SACL.
(D;;0xf0007;;;AN) Deny Anonymous (AN) all access. (1=Read + 2=Write + 4=Clear) (First ACE string in this SDDL)
(D;;0xf0007;;;BG) Deny Built-in Guests (BG) all access.
(A;;0xf0005;;;SY) Allow System Read and Clear (1=Read + 4=Clear), including DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER (indicated by the 0xf0000).
(A;;0x7;;;BA) Allow Built-in Admin READ, WRITE and CLEAR.
(A;;0x7;;;SO) Allow Server Operators READ, WRITE and CLEAR.
(A;;0x3;;;IU) Allow Interactive Users READ and WRITE.
(A;;0x3;;;SU) Allow Service accounts READ and WRITE.
You should add the proper ACE string so that your web page is able access the event logs. If your web page is running anonymously (in other words, running using Anonymous authentication in IIS), you will have to give the IUSR or the custom Anonymous account the proper permissions on this CustomSD reg key. If it is running on Windows Integrated Authentication, then the Authenticated Users group should have the required permissions.
To do this, append the below entry to the default value of CustomSD under the event log that you selected.
For the Authenticated Users group (in case of windows Integrated authentication): (A;;0x0003;;;AU) where AU = Authenticated Users
For IUSR or the custom configured Anonymous account (in case of Anonymous Authentication), find the SID for that account and then create one which looks like: (A;;0x3;;;S-1-5-21-1985444312-785446638-2839930158-1121) where the last field is the SID for the IUSR account on my machine.
For Windows Authentication on IIS and ASP.NET impersonation turned ON with a specific user account, find the SID for that impersonated account and then create a SDDL string which looks like: (A;;0x3;;;S-1-5-21-1985444312-785446638-2839930158-1121) where the last field is the SID for the impersonated account.
To give your group read permissions, add the following to the CustomSD value:
(A;;0x1;;; [Your Group Name/user account SID]) at the end of the current CustomSD string.
To give your group read and write permissions, add the following to the CustomSD value:
(A;;0x3;;; [Your Group Name/user account SID]) at the end of the current CustomSD string.
Windows Server 2008
Alternatively, on Windows 2008 server, if you are giving the users and groups in question read access to all event logs, you can just add them to the built-in Event Log Readers group. However, if you do not want to give access to ALL event logs you still have to resort to using the SDDL, for which you can use wevtutil utility. The following example demonstrates defining access to the System event log on Windows 2008 Server:
1. Open the command prompt, and run the following command to dump out the SDDL for the System log out to a txt file.
2. Open the text file and copy the channelAccess: entry
3. Add your user or group to this and run the following command to apply the new SDDL (Replace the O:BAG:XXXX with your SDDL String you created in the previous step):
Note: Once you edit this value and restart the computer, the new setting will take effect. Be certain that you fully understand SDDL and the default permissions that are placed on each event log before you use this procedure. Also, be certain to test any changes thoroughly before you implement them in a production environment, because you could accidentally configure the ACLs on an event log in such a way that no one can access it.
How to set event log security locally or by using Group Policy in Windows Server 2003
Event Log Security
Security Descriptor String Format
CustomSD EventLog value
How To Log Events from Active Server Pages
(http://go.microsoft.com/fwlink/?LinkId=151500)for other considerations.
Contact us for more help
Connect with Answer Desk for expert help.