You do have a machine.config file, otherwise you wouldn't be able to
run .NET. Look in the
{WindowsDirectory}\Microsoft.NET\Framework\v1.1.4322\CONFIG folder.
But that is besides the point.
You are are at cross purposes here. You have set up your ASP.NET
account as an administrator, but by turning on impersonation, you are
actually running the app under another identity (whatever is set in
machine.config, likely the logged on user as determined by IIS, which
is probably the anonymous user who has no rights).
You can find out what user account you are running under like so...
System.Security.Principal.WindowsIdentity wi;
wi = System.Security.Principal.WindowsIdentity.GetCurrent();
You can then either try turning off impersonation, and letting your
APS.NET administrator account (BTW, giving your ASP.NET account admin
priveleges is a bad idea), or set impersonation identity to a more
powerful user (also not a great idea).
Better idea is to create the event source with an app running under an
administrative user privileges. This is what is causing the error.
Writing to the event log doesn't require registry access, only
creating the source does.
Even better idea is to download log4net
http://logging.apache.org/log4net/ and not have to worry about it
yourself. You'll see there is an EventLog appender.
On 7/13/05, osos_bahgat <[EMAIL PROTECTED]> wrote:
> Hi All
> in my asp.net application I'm registering my errors in an event log.
> I'm using this method to log errors:
> --------
> protected void LogEvent (string message, EventLogEntryType entryType)
> {
> if(!EventLog.SourceExists
> ("OnlineCommunity.com"))
> {
> EventLog.CreateEventSource
> ("OnlineCommunity.com", "Application");
> }
> EventLog.WriteEntry ("OnlineCommunity",
> message, entryType);
> }
> ----------
> and i granted permissions to aspnet user as an admin user with full
> previlages and added this line of code to the web.config file:
> <identity impersonate = "true" />
> i'm working on a standalone pc with localhost, I don't have a
> machine.config file and when I'm trying to view the default page in
> the prowser the following exception appears:
> ----------
> 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 29: if(!EventLog.SourceExists
> ("OnlineCommunity.com"))
> Line 30: {
> Line 31: EventLog.CreateEventSource
> ("OnlineCommunity.com", "Application");
> Line 32: }
> Line 33: EventLog.WriteEntry
> ("OnlineCommunity", message, entryType);
> ------------------
> here is the contents of the web.config file:
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <system.web>
> <compilation
> defaultLanguage="c#"
> debug="true"
> />
>
> <customErrors
> mode="RemoteOnly"
> />
> <identity impersonate = "true" />
>
> <authentication mode="Forms">
> <forms name="OnlineCommunity" path="/"
> loginUrl="/OnlineCommunity/Modules/Users/Login.aspx"
> protection="All" timeout="30">
> </forms>
> </authentication>
> <authorization>
> <allow users="*" />
> </authorization>
> <trace
> enabled="false"
> requestLimit="10"
> pageOutput="false"
> traceMode="SortByTime"
> localOnly="true"
> />
> <sessionState
> mode="InProc"
> stateConnectionString="tcpip=127.0.0.1:42424"
> sqlConnectionString="data
> source=127.0.0.1;Trusted_Connection=yes"
> cookieless="false"
> timeout="20"
> />
> <globalization
> requestEncoding="utf-8"
> responseEncoding="utf-8"
> />
>
> </system.web>
>
> </configuration>
> ----------------------------
>
> can anyone tell me what can I do?
> thanks alot
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/