Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: page691 beginning ASP.NET, entrylog.aspx


Message #1 by "W P" <spin2k3@h...> on Thu, 11 Apr 2002 20:07:55
When I compile it I get the following error:

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.

Line 21:     if (!(EventLog.SourceExists(SourceName)))
Line 22:     {
Line 23:       EventLog.CreateEventSource(SourceName, LogName);
Line 24:     }
Line 25:     // Insert into Event Log;

So how to grant permission to this application?

Thanks for any help.

Message #2 by "Lauser, John" <LauserJ@h...> on Mon, 15 Apr 2002 09:00:41 -0400
The account that ASP.Net runs under does not have access to modify the
registry. When you try to write an eventlog entry with a source that
does not exist, it is supposed to create that entry. In this case, it is
failing. There are a couple solutions to this problem:

1. you could give a higher permission level to that account. I don't
recommend this though as it is a security risk.

2. create a quick console app that creates your log and sources for you
that you run manually. you will then have the sources you need to write
to the event log. I also suggest creating a default source and then
using that as a failover source. If a developer tries to log to a source
that does not exist, it will still capture it. Something like:

public static void Write(string sSource, string sEntry, string sType)
{
	System.Diagnostics.EventLog oEventLog =3D new
System.Diagnostics.EventLog();
	oEventLog.Log =3D "TestLog";
	if(!System.Diagnostics.EventLog.SourceExists(sSource))
	{
		string sMessage =3D "Attempted to write to non-existant
source '" + sSource + "'.\n\n" +
			"Source: " + sSource + "\n" +
			"Message: " + sEntry + "\n" +
			"Type: " + sType;
=09
System.Diagnostics.EventLog.WriteEntry("FailedWrite", sMessage,
EventLogEntryType.Error);
	}
	else
	{
		oEventLog.Source =3D sSource;

		EventLogEntryType oType =3D new EventLogEntryType();
		switch(sType)
		{
		case "Information":
			oType =3D EventLogEntryType.Information;
			break;
		case "Warning":
			oType =3D EventLogEntryType.Warning;
			break;
		case "Error":
			oType =3D EventLogEntryType.Error;
			break;
		case "SuccessAudit":
			oType =3D EventLogEntryType.SuccessAudit;
			break;
		case "FailureAudit":
			oType =3D EventLogEntryType.FailureAudit;
			break;
		}
		System.Diagnostics.EventLog.WriteEntry(sSource, sEntry,
oType);
	}
}

Your console app would create the TestLog log and the FailedWrite source
as the minimum. I decided to have my console parse through an xml file
so I could easily manage the sources without recompiling the exe.

Hope this helps.





-----Original Message-----
From: W P [mailto:spin2k3@h...]
Sent: Thursday, April 11, 2002 16:08
To: aspx_beginners
Subject: [aspx_beginners] page691 beginning ASP.NET, entrylog.aspx


When I compile it I get the following error:

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.

Line 21:     if (!(EventLog.SourceExists(SourceName)))
Line 22:     {
Line 23:       EventLog.CreateEventSource(SourceName, LogName);
Line 24:     }
Line 25:     // Insert into Event Log;

So how to grant permission to this application?

Thanks for any help.


  Return to Index