p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 1.0 (http://p2p.wrox.com/forumdisplay.php?f=26)
-   -   Security exception comes when writing to event log (http://p2p.wrox.com/showthread.php?t=6880)

s_vermani December 4th, 2003 02:21 PM

Security exception comes when writing to event log
I am trying to write to event log. When I run it I get a Security Exception message shown below. I am using windowsXP Pro and have administrator rights.

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:

Line 16: string LogName = "MyApplicationLog";
Line 17: string SourceName = "MyApplicationSource";
Line 18: if(!(EventLog.SourceExists(SourceName)))
Line 19: {
Line 20: EventLog.CreateEventSource(SourceName, LogName);

I read it on this forum that this can be fixed by changing the appEvent.evt file's security setting but I am not able to see the security tab for AppEvent.evt file. Please advice.



cjo December 17th, 2003 09:48 PM

If you don't alread have a web.config file do this:

Create a new file and save it as "web.config" in either your root directory or the directory that contains the code that is trying to create the event log. Copy and paste the xml contents below into this file. Be sure to replace your actual computername/username and password (the same info you use to log into Windows) in the "identity" element below. Then attempt to run the code again. I had the same error, and this worked for me. Good luck!

<?xml version="1.0" encoding="UTF-8" ?>
<identity impersonate="true" userName="COMPUTERNAME\USername" password="password" />

P.S. If you're already using a web.config file, then just add the identity element as shown above within the system.web element.

charul_shukla December 27th, 2003 06:05 AM


You need to disable simple file sharing option exists under the TOOLS>>FOLDER OPTIONS>>VIEW TAB. This is the last item in list of options you get in VIEW TAB. After that you are able to use the security tab for any folder while viewing its properties.

alandraper September 23rd, 2004 02:31 PM

Did you ever find an answer to this problem? I'm having the same difficulty... the only thing that has worked is to make my user an administrator of the machine, which is not acceptable.

  • In web.config, I have
  •     <identity impersonate="true" userName="mydomain\myuser" password="*****" />
  • Try to use
        EventLog.WriteEntry( "hello" );
  • I get the error
        System.Security.SecurityException: Requested registry access is not allowed.

mgevans October 21st, 2004 09:17 AM

That worked! I was able to add

<identity impersonate="true" userName="COMPUTERNAME\USername" password="password" />

to my existing web.config and continue on.

Now if I can only get my vendor to fix this problem... [xx(]

All times are GMT -4. The time now is 09:08 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.