Home All Groups Group Topic Archive Search About

web application can not access event log

Author
4 Apr 2005 10:17 PM
chuck rudolph
In the page_load, I have the following code:
PermissionSet ps = new PermissionSet(PermissionState.None);
ps.AddPermission(new EventLogPermission
EventLogPermissionAccess.Instrument,"."));
ps.Demand();
EventLogPermission ps2 = (EventLogPermission)
ps.GetPermission(typeof(EventLogPermission));

foreach (EventLogPermissionEntry psx in ps2.PermissionEntries)
{
    this.Response.Write("<p> Machine: " +
    psx.MachineName + " Bits: " + psx.PermissionAccess + " </p>");
}

When executed it writes:
Machine: . Bits: Instrument

Which would lead me to believe that I can write to an event log. But when I
then try to execute these two lines of code:

EventLog el = new EventLog("My Log",".","Login Category");
el.WriteEntry("Login is getting ready to run!");

ASP.Net (Microsoft .NET Framework Version:1.1.4322.2032) throws the
following exception:
Exception Details: System.Security.SecurityException: Requested registry
access is not allowed.

Any ideas?

Author
5 Apr 2005 12:15 AM
chuck rudolph
Here's some more info that may help my helpers ---

The error occurs when this code runs as an anonymous user. If I add an
identity element to web.config and impersonate a "user" all is well as long
as I give the user NTFS write access to .net\framework\ver\temporary asp.net
files\ directory.

My read of the doc did not lead me this way, but I got to thinking that
there might be a "deny" access policy somewhere in the tree and gave it a try.

So what is the "best practice" recommendation for a web applicaton that
allows anonymous users (mine uses forms authentication via a sql server ) and
needs to write to an event log?

Thanks...Chuck

Show quoteHide quote
"chuck rudolph" wrote:

> In the page_load, I have the following code:
> PermissionSet ps = new PermissionSet(PermissionState.None);
> ps.AddPermission(new EventLogPermission
> EventLogPermissionAccess.Instrument,"."));
> ps.Demand();
> EventLogPermission ps2 = (EventLogPermission)
> ps.GetPermission(typeof(EventLogPermission));
>
> foreach (EventLogPermissionEntry psx in ps2.PermissionEntries)
> {
>     this.Response.Write("<p> Machine: " +
>     psx.MachineName + " Bits: " + psx.PermissionAccess + " </p>");
> }
>
> When executed it writes:
> Machine: . Bits: Instrument
>
> Which would lead me to believe that I can write to an event log. But when I
> then try to execute these two lines of code:
>
> EventLog el = new EventLog("My Log",".","Login Category");
> el.WriteEntry("Login is getting ready to run!");
>
> ASP.Net (Microsoft .NET Framework Version:1.1.4322.2032) throws the
> following exception:
> Exception Details: System.Security.SecurityException: Requested registry
> access is not allowed.
>
> Any ideas?
>
>
>
Author
5 Apr 2005 7:19 PM
Joseph MCAD
April 5, 2005

      The trouble is that your web application is not granted "Full Trust".
This is a good thing. You are granted the EventLogPermission, but what is not
known by many people is that there is a hidden demand for full trust, when
the methods are called. However, you can read/write to the eventlog without
full trust IF you do not create event sources. You must go to your command
prompt and open the registry editor to set this up. Type "regedit" at the
command prompt. Go to:
HKEY_Local_Machine\SYSTEM\CurrentControlSet\Services\EventLog\Application

Create a new node under the Application node. Name this new node the name of
your web application. If your application is named Northwind or MySite, then
name this new node exactly as your site. You can then use the
Diagnostics.EventLog class as long as you do not create event sources. By
modifying the registry in this way, you pre-made the event source. Just make
sure to set the source property on the eventlog class to the name of your web
application. Keep in mind that you might not be able to do this for the
Security or System eventlogs. I have found it only works under the
Application (I haven't tried a custom log.) and also you cannot be
"registered" by creating nodes under more than one log. Just make sure that
your web application is granted the EventLogPermission with read/write
access. You do not have to worry about the fulltrust demand anymore! Hope
this helps and have a great day!



   Joseph MCAD



Show quoteHide quote
"chuck rudolph" wrote:

> Here's some more info that may help my helpers ---
>
> The error occurs when this code runs as an anonymous user. If I add an
> identity element to web.config and impersonate a "user" all is well as long
> as I give the user NTFS write access to .net\framework\ver\temporary asp.net
> files\ directory.
>
> My read of the doc did not lead me this way, but I got to thinking that
> there might be a "deny" access policy somewhere in the tree and gave it a try.
>
> So what is the "best practice" recommendation for a web applicaton that
> allows anonymous users (mine uses forms authentication via a sql server ) and
> needs to write to an event log?
>
> Thanks...Chuck
>
> "chuck rudolph" wrote:
>
> > In the page_load, I have the following code:
> > PermissionSet ps = new PermissionSet(PermissionState.None);
> > ps.AddPermission(new EventLogPermission
> > EventLogPermissionAccess.Instrument,"."));
> > ps.Demand();
> > EventLogPermission ps2 = (EventLogPermission)
> > ps.GetPermission(typeof(EventLogPermission));
> >
> > foreach (EventLogPermissionEntry psx in ps2.PermissionEntries)
> > {
> >     this.Response.Write("<p> Machine: " +
> >     psx.MachineName + " Bits: " + psx.PermissionAccess + " </p>");
> > }
> >
> > When executed it writes:
> > Machine: . Bits: Instrument
> >
> > Which would lead me to believe that I can write to an event log. But when I
> > then try to execute these two lines of code:
> >
> > EventLog el = new EventLog("My Log",".","Login Category");
> > el.WriteEntry("Login is getting ready to run!");
> >
> > ASP.Net (Microsoft .NET Framework Version:1.1.4322.2032) throws the
> > following exception:
> > Exception Details: System.Security.SecurityException: Requested registry
> > access is not allowed.
> >
> > Any ideas?
> >
> >
> >
Author
5 Apr 2005 9:43 PM
chuck rudolph
Joseph (& Nicole), Thanks. Joeseph's words on the application log do work. I
need to attempt a like fix to my custom log file and see if I can make it
work. I will post a solution if I find one.

On the other side of the coin, does anyone know why the permissionSet.Demand
(or Assert) complete normally -- leading me to believe that I can create the
log and log source?

Thanks...Chuck
Author
5 Apr 2005 10:17 PM
Joseph MCAD
April 5, 2005

    Hi Chuck,

       What permissions are in the permissionset that you are
demanding/asserting? If you talking about the Eventlogpermission, it is
working, because you are granted that permission. Just to let you know... If
you are granted FullTrust then NO permission demands will even be evaluated.
That permission set BYPASSES checks of all kinds, even if they are for custom
permissions that you have not granted that assembly. This could be why your
permissionset is completing, but you should be able to access the eventlog
without failing, so I don't think so. If you want to be granted all normal,
builtin permissions, while STILL evaluating demands/asserts/etc. then you
should run not under FullTrust but Everything. Everything will grant you all
normal, builtin permissions while still evaluating CAS. I hope this helps and
be sure to post about your custom log and the registry. Thanks, you are
saving me the experiment!


            Joseph MCAD



Show quoteHide quote
"chuck rudolph" wrote:

> Joseph (& Nicole), Thanks. Joeseph's words on the application log do work. I
> need to attempt a like fix to my custom log file and see if I can make it
> work. I will post a solution if I find one.
>
> On the other side of the coin, does anyone know why the permissionSet.Demand
> (or Assert) complete normally -- leading me to believe that I can create the
> log and log source?
>
> Thanks...Chuck
>
>
Author
5 Apr 2005 11:41 PM
chuck rudolph
Joesph, The reason I am confused is the code first "demanded" a permission
set of EventLogPermissionAccess.Instrument. MSDN says "The EventLog can read
or write to existing logs, and create event sources and logs." The demand
succeeded. That to me says that I have the rights to (1) create event logs
and (2) create event sources and (3) read and write logs. We both know that
is not true, so what part of this don't I get. (The actual code that I ran is
listed at the beginning of the first post. I start with "none", although the
task is running with "full")

Thanks. (BTW: the test worked, see the main line post.) ...Chuck

Show quoteHide quote
"Joseph MCAD" wrote:

>
>   April 5, 2005
>
>     Hi Chuck,
>
>        What permissions are in the permissionset that you are
> demanding/asserting? If you talking about the Eventlogpermission, it is
> working, because you are granted that permission. Just to let you know... If
> you are granted FullTrust then NO permission demands will even be evaluated.
> That permission set BYPASSES checks of all kinds, even if they are for custom
> permissions that you have not granted that assembly. This could be why your
> permissionset is completing, but you should be able to access the eventlog
> without failing, so I don't think so. If you want to be granted all normal,
> builtin permissions, while STILL evaluating demands/asserts/etc. then you
> should run not under FullTrust but Everything. Everything will grant you all
> normal, builtin permissions while still evaluating CAS. I hope this helps and
> be sure to post about your custom log and the registry. Thanks, you are
> saving me the experiment!
>
>                                                                             
>             Joseph MCAD
>
>
>
> "chuck rudolph" wrote:
>
> > Joseph (& Nicole), Thanks. Joeseph's words on the application log do work. I
> > need to attempt a like fix to my custom log file and see if I can make it
> > work. I will post a solution if I find one.
> >
> > On the other side of the coin, does anyone know why the permissionSet.Demand
> > (or Assert) complete normally -- leading me to believe that I can create the
> > log and log source?
> >
> > Thanks...Chuck
> >
> >
Author
5 Apr 2005 11:53 PM
Joseph MCAD
April 5, 2005

     I see the permission set you mean. This confusion is well founded. What
is happening is when you demand the eventlogpermission.instrument it
succeeds, because you are granted that permission. BUT when you go to call
eventlog.createventsource, the CreateEventSource method secretly demands the
FullTrust permission set. It would be as if I created this following method
in a custom library for you to use:

<FileIoPermission(SecurityAction.Demand, all:="c:\myfolder")> _
Public Sub DoWorkForYou()

    ' Before doing work, secretly demand UNRESTRICTED access to file system,
EVEN Though the security attribute above only asks for c:\myfolder

   dim permset as new FileIoPermission(PermissionState.Unrestricted)     
   permset.Demand 'Secretly Demands Unrestricted FileIOPermission

   'Now do promised work
End Sub

If you ran permview to analyze the requested minimum permissions, then it
would look like you just have to be able to access c:\myfolder. You would be
granted access to this method. However, the method Secretly demands the
unrestricted FileIOPermission IN the method and therefore is not displayed by
permview. This causes the confusion and explains why some methods work and
some don't even though you Should be able to access them all. I hope this
makes sense and thanks for reporting the result of the experiment! :-)


           Joseph MCAD


Show quoteHide quote
"chuck rudolph" wrote:

> Joesph, The reason I am confused is the code first "demanded" a permission
> set of EventLogPermissionAccess.Instrument. MSDN says "The EventLog can read
> or write to existing logs, and create event sources and logs." The demand
> succeeded. That to me says that I have the rights to (1) create event logs
> and (2) create event sources and (3) read and write logs. We both know that
> is not true, so what part of this don't I get. (The actual code that I ran is
> listed at the beginning of the first post. I start with "none", although the
> task is running with "full")
>
> Thanks. (BTW: the test worked, see the main line post.) ...Chuck
>
> "Joseph MCAD" wrote:
>
> >
> >   April 5, 2005
> >
> >     Hi Chuck,
> >
> >        What permissions are in the permissionset that you are
> > demanding/asserting? If you talking about the Eventlogpermission, it is
> > working, because you are granted that permission. Just to let you know... If
> > you are granted FullTrust then NO permission demands will even be evaluated.
> > That permission set BYPASSES checks of all kinds, even if they are for custom
> > permissions that you have not granted that assembly. This could be why your
> > permissionset is completing, but you should be able to access the eventlog
> > without failing, so I don't think so. If you want to be granted all normal,
> > builtin permissions, while STILL evaluating demands/asserts/etc. then you
> > should run not under FullTrust but Everything. Everything will grant you all
> > normal, builtin permissions while still evaluating CAS. I hope this helps and
> > be sure to post about your custom log and the registry. Thanks, you are
> > saving me the experiment!
> >
> >                                                                             
> >             Joseph MCAD
> >
> >
> >
> > "chuck rudolph" wrote:
> >
> > > Joseph (& Nicole), Thanks. Joeseph's words on the application log do work. I
> > > need to attempt a like fix to my custom log file and see if I can make it
> > > work. I will post a solution if I find one.
> > >
> > > On the other side of the coin, does anyone know why the permissionSet.Demand
> > > (or Assert) complete normally -- leading me to believe that I can create the
> > > log and log source?
> > >
> > > Thanks...Chuck
> > >
> > >
Author
6 Apr 2005 5:03 AM
chuck rudolph
So it's as Dean Wormer said: my code is running on double secret probation?!
No wonder MCADs (I'm one too) make the big $'s. Thanks...

Show quoteHide quote
"Joseph MCAD" wrote:

>
>    April 5, 2005
>
>      I see the permission set you mean. This confusion is well founded. What
> is happening is when you demand the eventlogpermission.instrument it
> succeeds, because you are granted that permission. BUT when you go to call
> eventlog.createventsource, the CreateEventSource method secretly demands the
> FullTrust permission set. It would be as if I created this following method
> in a custom library for you to use:
>
> <FileIoPermission(SecurityAction.Demand, all:="c:\myfolder")> _
> Public Sub DoWorkForYou()
>     
>     ' Before doing work, secretly demand UNRESTRICTED access to file system,
> EVEN Though the security attribute above only asks for c:\myfolder
>
>    dim permset as new FileIoPermission(PermissionState.Unrestricted)     
>    permset.Demand 'Secretly Demands Unrestricted FileIOPermission
>
>    'Now do promised work
> End Sub
>
> If you ran permview to analyze the requested minimum permissions, then it
> would look like you just have to be able to access c:\myfolder. You would be
> granted access to this method. However, the method Secretly demands the
> unrestricted FileIOPermission IN the method and therefore is not displayed by
> permview. This causes the confusion and explains why some methods work and
> some don't even though you Should be able to access them all. I hope this
> makes sense and thanks for reporting the result of the experiment! :-)
>
>                                                                             
>            Joseph MCAD
>
>
> "chuck rudolph" wrote:
>
> > Joesph, The reason I am confused is the code first "demanded" a permission
> > set of EventLogPermissionAccess.Instrument. MSDN says "The EventLog can read
> > or write to existing logs, and create event sources and logs." The demand
> > succeeded. That to me says that I have the rights to (1) create event logs
> > and (2) create event sources and (3) read and write logs. We both know that
> > is not true, so what part of this don't I get. (The actual code that I ran is
> > listed at the beginning of the first post. I start with "none", although the
> > task is running with "full")
> >
> > Thanks. (BTW: the test worked, see the main line post.) ...Chuck
> >
> > "Joseph MCAD" wrote:
> >
> > >
> > >   April 5, 2005
> > >
> > >     Hi Chuck,
> > >
> > >        What permissions are in the permissionset that you are
> > > demanding/asserting? If you talking about the Eventlogpermission, it is
> > > working, because you are granted that permission. Just to let you know... If
> > > you are granted FullTrust then NO permission demands will even be evaluated.
> > > That permission set BYPASSES checks of all kinds, even if they are for custom
> > > permissions that you have not granted that assembly. This could be why your
> > > permissionset is completing, but you should be able to access the eventlog
> > > without failing, so I don't think so. If you want to be granted all normal,
> > > builtin permissions, while STILL evaluating demands/asserts/etc. then you
> > > should run not under FullTrust but Everything. Everything will grant you all
> > > normal, builtin permissions while still evaluating CAS. I hope this helps and
> > > be sure to post about your custom log and the registry. Thanks, you are
> > > saving me the experiment!
> > >
> > >                                                                             
> > >             Joseph MCAD
> > >
> > >
> > >
> > > "chuck rudolph" wrote:
> > >
> > > > Joseph (& Nicole), Thanks. Joeseph's words on the application log do work. I
> > > > need to attempt a like fix to my custom log file and see if I can make it
> > > > work. I will post a solution if I find one.
> > > >
> > > > On the other side of the coin, does anyone know why the permissionSet.Demand
> > > > (or Assert) complete normally -- leading me to believe that I can create the
> > > > log and log source?
> > > >
> > > > Thanks...Chuck
> > > >
> > > >
Author
6 Apr 2005 12:00 PM
Nicole Calinoiu
"Joseph MCAD" <JosephM***@discussions.microsoft.com> wrote in message
news:7C5FBBEB-B928-4D2F-8190-AD036C1EE65E@microsoft.com...
<snip>
> Just to let you know... If
> you are granted FullTrust then NO permission demands will even be
> evaluated.

That's not true.  If an assembly is granted full trust, then no demands for
permissions that implement IUnrestrictedPermission should fail when
evaluated against that assembly.  However, the demands will indeed evaluate,
and a full demand could still fail due to the presence of partially trusted
assemblies on the call stack.  CAS permission demands will only be
completely circumvented if CAS is disabled on the machine on which the code
is running, but this has nothing to do with the fully vs partially trusted
status of any given assembly.




Show quoteHide quote
> That permission set BYPASSES checks of all kinds, even if they are for
> custom
> permissions that you have not granted that assembly.  This could be why
> your
> permissionset is completing, but you should be able to access the eventlog
> without failing, so I don't think so. If you want to be granted all
> normal,
> builtin permissions, while STILL evaluating demands/asserts/etc. then you
> should run not under FullTrust but Everything. Everything will grant you
> all
> normal, builtin permissions while still evaluating CAS. I hope this helps
> and
> be sure to post about your custom log and the registry. Thanks, you are
> saving me the experiment!
>
>
>            Joseph MCAD
>
>
>
> "chuck rudolph" wrote:
>
>> Joseph (& Nicole), Thanks. Joeseph's words on the application log do
>> work. I
>> need to attempt a like fix to my custom log file and see if I can make it
>> work. I will post a solution if I find one.
>>
>> On the other side of the coin, does anyone know why the
>> permissionSet.Demand
>> (or Assert) complete normally -- leading me to believe that I can create
>> the
>> log and log source?
>>
>> Thanks...Chuck
>>
>>
Author
6 Apr 2005 11:52 AM
Nicole Calinoiu
"chuck rudolph" <chuckrudo***@discussions.microsoft.com> wrote in message
news:9AE36CAF-59D9-431A-AEB7-6C2928EE87BE@microsoft.com...
<snip>
> On the other side of the coin, does anyone know why the
> permissionSet.Demand
> (or Assert) complete normally -- leading me to believe that I can create
> the
> log and log source?

The problem was caused purely by the user not having adequate permissions to
the registry key under Windows security settings.  Code access security was
not involved in this particular failure.  Your confusion is probably at
least partially caused by the fact that a SecurityException (which is
supposed to be associated with CAS permission failures) was thrown instead
of an UnauthorizedAccessException.  The latter would be more appropriate in
this case, but that's unfortunately not how the relevant method was
implemented.



Show quoteHide quote
>
> Thanks...Chuck
>
>
Author
6 Apr 2005 8:21 PM
chuck rudolph
Nicole, I can buy what you say about the failing being related to windows
security and not CAS because when I impersonate the administrator it works
just peachy. But I can not find what windows security needs to be set where.
I figured if I changed the "permissions" on the event log in the regedit I
could write to the registry. But selecting both IUser_ and ASP.NET (I'm on
XP) do not let me write to the event log.

Further I have found that depending on the name of the log file I create, I
can either read/write it or not. This part is really confusing. (All the
names are 8 characters or less) I can't find a rhyme or reason to which name
will let a web application read/write and which name will throw an error in
the web application.

....Chuck

Show quoteHide quote
"Nicole Calinoiu" wrote:
> The problem was caused purely by the user not having adequate permissions to
> the registry key under Windows security settings.  Code access security was
> not involved in this particular failure.  Your confusion is probably at
> least partially caused by the fact that a SecurityException (which is
> supposed to be associated with CAS permission failures) was thrown instead
> of an UnauthorizedAccessException.  The latter would be more appropriate in
> this case, but that's unfortunately not how the relevant method was
> implemented.
Author
6 Apr 2005 8:44 PM
Joseph MCAD
April 6, 2005

   I once read in my security book how to configure the NTFS permissions on
the eventlog class, but I never got around to trying it. I just looked it
back up and appearently the process account (ASPNET) needs to have these
permissions granted to it on the key below to create eventsources:

hkey_local_machine\system\currentcontrolset\services\eventlog

You need to grant ASPNET on this key the following permissions:  (you will
have to get into the advanced permission settings)

Query Value
Set Value
Create SubKey
Enumerate SubKeys
Notify
Read

If you try this, be sure to let me know the outcome! :-)



                       Joseph MCAD



Show quoteHide quote
"chuck rudolph" <chuckrudo***@discussions.microsoft.com> wrote in message
news:37C456C2-6558-4320-8C8C-84D06D8424C9@microsoft.com...
> Nicole, I can buy what you say about the failing being related to windows
> security and not CAS because when I impersonate the administrator it works
> just peachy. But I can not find what windows security needs to be set
> where.
> I figured if I changed the "permissions" on the event log in the regedit I
> could write to the registry. But selecting both IUser_ and ASP.NET (I'm on
> XP) do not let me write to the event log.
>
> Further I have found that depending on the name of the log file I create,
> I
> can either read/write it or not. This part is really confusing. (All the
> names are 8 characters or less) I can't find a rhyme or reason to which
> name
> will let a web application read/write and which name will throw an error
> in
> the web application.
>
> ...Chuck
>
> "Nicole Calinoiu" wrote:
>> The problem was caused purely by the user not having adequate permissions
>> to
>> the registry key under Windows security settings.  Code access security
>> was
>> not involved in this particular failure.  Your confusion is probably at
>> least partially caused by the fact that a SecurityException (which is
>> supposed to be associated with CAS permission failures) was thrown
>> instead
>> of an UnauthorizedAccessException.  The latter would be more appropriate
>> in
>> this case, but that's unfortunately not how the relevant method was
>> implemented.
>
Author
7 Apr 2005 3:57 AM
chuck rudolph
Joseph, I am creating the keys in a windows app. The Asp.Net worker process
gets it's security violation trying to "read" the registry. My test rountine
was doing an EnventLog.SourceExists("mySource") and was getting an exception
before I even tried to write the log.

When I compare the permissions in Regedit, the permissions of a log file
that works and one that does not apprear to be the same. So I am going to try
Joe K's suggest of regmon/filemon ..Chuck

Show quoteHide quote
"Joseph MCAD" wrote:

>
> April 6, 2005
>
>    I once read in my security book how to configure the NTFS permissions on
> the eventlog class, but I never got around to trying it. I just looked it
> back up and appearently the process account (ASPNET) needs to have these
> permissions granted to it on the key below to create eventsources:
>
> hkey_local_machine\system\currentcontrolset\services\eventlog
>
>  You need to grant ASPNET on this key the following permissions:  (you will
> have to get into the advanced permission settings)
>
> Query Value
> Set Value
> Create SubKey
> Enumerate SubKeys
> Notify
> Read
>
> If you try this, be sure to let me know the outcome! :-)
>
>
>                                                                             
>                        Joseph MCAD
>
>
>
Author
7 Apr 2005 2:11 AM
Joe Kaplan (MVP - ADSI)
I'd highly recommend using regmon and filemon to find which file or key is
getting the access denied and figure out which account is causing the
problem.  Then, if that doesn't give you enough information to fix the
issue, enable object auditing in local security policy and set the SACL on
the object in question to enable audits.  Then the security event log will
give you more details.

I got lost on the last exchange though.  Are you still having trouble
creating event sources from ASP.NET or just writing to them?  Generally, you
create your event sources during deployment with an admin account to avoid
these issues.  However, if the application itself can't write to the log,
then that is a different problem.

Joe K.

Show quoteHide quote
"chuck rudolph" <chuckrudo***@discussions.microsoft.com> wrote in message
news:37C456C2-6558-4320-8C8C-84D06D8424C9@microsoft.com...
> Nicole, I can buy what you say about the failing being related to windows
> security and not CAS because when I impersonate the administrator it works
> just peachy. But I can not find what windows security needs to be set
> where.
> I figured if I changed the "permissions" on the event log in the regedit I
> could write to the registry. But selecting both IUser_ and ASP.NET (I'm on
> XP) do not let me write to the event log.
>
> Further I have found that depending on the name of the log file I create,
> I
> can either read/write it or not. This part is really confusing. (All the
> names are 8 characters or less) I can't find a rhyme or reason to which
> name
> will let a web application read/write and which name will throw an error
> in
> the web application.
>
> ...Chuck
>
Author
7 Apr 2005 3:51 AM
chuck rudolph
Joe, It's the web application that can not write to the event log. I have a
windows progam that creates the custom logs and registers the sources. The
windows program always works (it's running as an administrator). Note that
only SOME of the logs that the windows program creates can not be written -
so something is screwy in my development machines registry I think. I moved
the log create utility and web application to a test machine and it worked
just fine with one of the log file names that was giving me trouble on the
development box. For my development box, I jammed an <identity> element with
impersonation of an admin in the web.config so I could do work. I will see if
I can get regmon and filemon to tell me what is up.

....Chuck

Show quoteHide quote
"Joe Kaplan (MVP - ADSI)" wrote:

> I'd highly recommend using regmon and filemon to find which file or key is
> getting the access denied and figure out which account is causing the
> problem.  Then, if that doesn't give you enough information to fix the
> issue, enable object auditing in local security policy and set the SACL on
> the object in question to enable audits.  Then the security event log will
> give you more details.
>
> I got lost on the last exchange though.  Are you still having trouble
> creating event sources from ASP.NET or just writing to them?  Generally, you
> create your event sources during deployment with an admin account to avoid
> these issues.  However, if the application itself can't write to the log,
> then that is a different problem.
>
> Joe K.
>
Author
7 Apr 2005 4:33 AM
chuck rudolph
Joe, Regmon did the trick. The security event log on my development machine
on had ONLY two defined members that allowed access -- administrators and
system both with special. So your average guy could not read the security
registery and that's where the error was being thrown. If the log file name
"sorted" before security, aspnet found what it was looking for and wrote the
log entry. Otherwise, it tried to look in the security log and got booted.
Adding "read" access for the asp.net worker process solved the problem. In
checking another pc, it looks like ordinary "users" should have read access.

Thanks to everyone for the help...Chuck

Show quoteHide quote
"Joe Kaplan (MVP - ADSI)" wrote:

> I'd highly recommend using regmon and filemon to find which file or key is
> getting the access denied and figure out which account is causing the
> problem.  Then, if that doesn't give you enough information to fix the
> issue, enable object auditing in local security policy and set the SACL on
> the object in question to enable audits.  Then the security event log will
> give you more details.
>
> I got lost on the last exchange though.  Are you still having trouble
> creating event sources from ASP.NET or just writing to them?  Generally, you
> create your event sources during deployment with an admin account to avoid
> these issues.  However, if the application itself can't write to the log,
> then that is a different problem.
>
> Joe K.
>
Author
7 Apr 2005 11:14 AM
Nicole Calinoiu
"chuck rudolph" <chuckrudo***@discussions.microsoft.com> wrote in message
news:7B45333E-C3CD-4F6B-8062-F500A08B1963@microsoft.com...
> Joe, Regmon did the trick. The security event log on my development
> machine
> on had ONLY two defined members that allowed access -- administrators and
> system both with special. So your average guy could not read the security
> registery and that's where the error was being thrown. If the log file
> name
> "sorted" before security, aspnet found what it was looking for and wrote
> the
> log entry.

Interesting...  I'll try to repro.


> Otherwise, it tried to look in the security log and got booted.
> Adding "read" access for the asp.net worker process solved the problem. In
> checking another pc, it looks like ordinary "users" should have read
> access.

No, they really shouldn't.  All sorts of things end up in the security event
log that should not be read by anyone other than very highly privileged
users.  For example, when a user accidentally puts their password into the
user name text box during a login, the password will end up getting stored
as a user name in the security event log (assuming login logging is
activated).  Since the user will then repeat the login with their proper
user name, viewing of the event log will potentially reveal user
name-password pairs.  Do you really want the ASP.NET account to be able to
read this data?  If there really is a problem wrt the sorting of the event
log names, a much safer workaround would be to use a name that sorts before
"security".



Show quoteHide quote
>
> Thanks to everyone for the help...Chuck
>
> "Joe Kaplan (MVP - ADSI)" wrote:
>
>> I'd highly recommend using regmon and filemon to find which file or key
>> is
>> getting the access denied and figure out which account is causing the
>> problem.  Then, if that doesn't give you enough information to fix the
>> issue, enable object auditing in local security policy and set the SACL
>> on
>> the object in question to enable audits.  Then the security event log
>> will
>> give you more details.
>>
>> I got lost on the last exchange though.  Are you still having trouble
>> creating event sources from ASP.NET or just writing to them?  Generally,
>> you
>> create your event sources during deployment with an admin account to
>> avoid
>> these issues.  However, if the application itself can't write to the log,
>> then that is a different problem.
>>
>> Joe K.
>>
>
Author
7 Apr 2005 12:01 PM
Nicole Calinoiu
I was able to reproduce the name sorting problem.  The same issue wrt
attempting to read the security log key occurs regardless of whether one
specifies the log name or not, which is rather silly.  The good news is that
the problem doesn't occur in Whidbey (Feb CTP), so it looks like someone at
Microsoft is already aware of the issue.  Unformtunately, it would appear
that, even in Whidbey, a provided log name isn't being used as a hint when
confirming the source existence, but that's more of a potential performance
issue than a functional block like you're seeing in v. 1.x...



Show quoteHide quote
"chuck rudolph" <chuckrudo***@discussions.microsoft.com> wrote in message
news:7B45333E-C3CD-4F6B-8062-F500A08B1963@microsoft.com...
> Joe, Regmon did the trick. The security event log on my development
> machine
> on had ONLY two defined members that allowed access -- administrators and
> system both with special. So your average guy could not read the security
> registery and that's where the error was being thrown. If the log file
> name
> "sorted" before security, aspnet found what it was looking for and wrote
> the
> log entry. Otherwise, it tried to look in the security log and got booted.
> Adding "read" access for the asp.net worker process solved the problem. In
> checking another pc, it looks like ordinary "users" should have read
> access.
>
> Thanks to everyone for the help...Chuck
>
> "Joe Kaplan (MVP - ADSI)" wrote:
>
>> I'd highly recommend using regmon and filemon to find which file or key
>> is
>> getting the access denied and figure out which account is causing the
>> problem.  Then, if that doesn't give you enough information to fix the
>> issue, enable object auditing in local security policy and set the SACL
>> on
>> the object in question to enable audits.  Then the security event log
>> will
>> give you more details.
>>
>> I got lost on the last exchange though.  Are you still having trouble
>> creating event sources from ASP.NET or just writing to them?  Generally,
>> you
>> create your event sources during deployment with an admin account to
>> avoid
>> these issues.  However, if the application itself can't write to the log,
>> then that is a different problem.
>>
>> Joe K.
>>
>
Author
6 Apr 2005 11:40 AM
Nicole Calinoiu
"Joseph MCAD" <JosephM***@discussions.microsoft.com> wrote in message
news:DC81A148-0926-479F-893C-0A0EBDDBA8F9@microsoft.com...
>
>   April 5, 2005
>
>      The trouble is that your web application is not granted "Full Trust".

No, it's not.  If Chuck's assembly were not granted full trust under CAS, a
SecurityException would be thrown when his code is JITed (due to the
LinkDemand for full trust on the EventLog class).  Since his code actually
runs to the point of attempting to create the log entry in the registry,
either his code is fully trusted (or, less likely, CAS is disabled on his
machine).


> This is a good thing. You are granted the EventLogPermission, but what is
> not
> known by many people is that there is a hidden demand for full trust, when
> the methods are called. However, you can read/write to the eventlog
> without
> full trust IF you do not create event sources.

Not true.  The registry access error in this case is due to user
permissions, not CAS permissions.  In addition, due to the LinkDemand for
full trust on the EventLog class, its direct caller must be fully trusted,
regardless of whether event sources are being created or not.  However, one
could still write event log entries from a partially trusted application by
brokering the call through a fully trusted library.



Show quoteHide quote
> You must go to your command
> prompt and open the registry editor to set this up. Type "regedit" at the
> command prompt. Go to:
> HKEY_Local_Machine\SYSTEM\CurrentControlSet\Services\EventLog\Application
>
> Create a new node under the Application node. Name this new node the name
> of
> your web application. If your application is named Northwind or MySite,
> then
> name this new node exactly as your site. You can then use the
> Diagnostics.EventLog class as long as you do not create event sources. By
> modifying the registry in this way, you pre-made the event source. Just
> make
> sure to set the source property on the eventlog class to the name of your
> web
> application. Keep in mind that you might not be able to do this for the
> Security or System eventlogs. I have found it only works under the
> Application (I haven't tried a custom log.) and also you cannot be
> "registered" by creating nodes under more than one log. Just make sure
> that
> your web application is granted the EventLogPermission with read/write
> access. You do not have to worry about the fulltrust demand anymore! Hope
> this helps and have a great day!
>
>
>
>   Joseph MCAD
>
>
>
> "chuck rudolph" wrote:
>
>> Here's some more info that may help my helpers ---
>>
>> The error occurs when this code runs as an anonymous user. If I add an
>> identity element to web.config and impersonate a "user" all is well as
>> long
>> as I give the user NTFS write access to .net\framework\ver\temporary
>> asp.net
>> files\ directory.
>>
>> My read of the doc did not lead me this way, but I got to thinking that
>> there might be a "deny" access policy somewhere in the tree and gave it a
>> try.
>>
>> So what is the "best practice" recommendation for a web applicaton that
>> allows anonymous users (mine uses forms authentication via a sql server )
>> and
>> needs to write to an event log?
>>
>> Thanks...Chuck
>>
>> "chuck rudolph" wrote:
>>
>> > In the page_load, I have the following code:
>> > PermissionSet ps = new PermissionSet(PermissionState.None);
>> > ps.AddPermission(new EventLogPermission
>> > EventLogPermissionAccess.Instrument,"."));
>> > ps.Demand();
>> > EventLogPermission ps2 = (EventLogPermission)
>> > ps.GetPermission(typeof(EventLogPermission));
>> >
>> > foreach (EventLogPermissionEntry psx in ps2.PermissionEntries)
>> > {
>> >     this.Response.Write("<p> Machine: " +
>> > psx.MachineName + " Bits: " + psx.PermissionAccess + " </p>");
>> > }
>> >
>> > When executed it writes:
>> > Machine: . Bits: Instrument
>> >
>> > Which would lead me to believe that I can write to an event log. But
>> > when I
>> > then try to execute these two lines of code:
>> >
>> > EventLog el = new EventLog("My Log",".","Login Category");
>> > el.WriteEntry("Login is getting ready to run!");
>> >
>> > ASP.Net (Microsoft .NET Framework Version:1.1.4322.2032) throws the
>> > following exception:
>> > Exception Details: System.Security.SecurityException: Requested
>> > registry
>> > access is not allowed.
>> >
>> > Any ideas?
>> >
>> >
>> >
Author
5 Apr 2005 9:53 AM
Nicole Calinoiu
"chuck rudolph" <chuckrudo***@discussions.microsoft.com> wrote in message
news:B0697B52-4EAD-4F38-B4B4-B2F8CB5C5242@microsoft.com...
<snip>
> ASP.Net (Microsoft .NET Framework Version:1.1.4322.2032) throws the
> following exception:
> Exception Details: System.Security.SecurityException: Requested registry
> access is not allowed.

When an event log source is first used, it gets saved under the appropriate
event log type in the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog.  The code
creating the entry requires permissions to create the new key, as does the
user account under which the code is running.  It's generally not a great
idea to grant this permission to either the code or users of a web
applications.  Instead, you should consider creating the event log outside
of the web application (e.g.: via an installer or a configuration utility
run by an admin user).
Author
5 Apr 2005 11:51 PM
chuck rudolph
Nicole and Joseph put me on the correct track. Here's the scoop. I wrote a
windows app (just because I had one laying around) that did a
EventLog.CreateEventSource("sourceName","logName") for a couple sources for a
"custom log". Then in my web application I did a EventLog el = new
EventLog("logName", ".", "sourceName") and then el.WriteEntry("stuff to log")
and the custom log was written without issue with the web application running
as the standard anonymous user.

So the key seems to be to do not attempt to create a eventLog or an
eventSource in a web application and you will be okay.  Joseph is still
educating me on the permissions, so check the long thread if you want those
details....Chuck

Show quoteHide quote
"chuck rudolph" wrote:

> In the page_load, I have the following code:
> PermissionSet ps = new PermissionSet(PermissionState.None);
> ps.AddPermission(new EventLogPermission
> EventLogPermissionAccess.Instrument,"."));
> ps.Demand();
> EventLogPermission ps2 = (EventLogPermission)
> ps.GetPermission(typeof(EventLogPermission));
>
> foreach (EventLogPermissionEntry psx in ps2.PermissionEntries)
> {
>     this.Response.Write("<p> Machine: " +
>     psx.MachineName + " Bits: " + psx.PermissionAccess + " </p>");
> }
>
> When executed it writes:
> Machine: . Bits: Instrument
>
> Which would lead me to believe that I can write to an event log. But when I
> then try to execute these two lines of code:
>
> EventLog el = new EventLog("My Log",".","Login Category");
> el.WriteEntry("Login is getting ready to run!");
>
> ASP.Net (Microsoft .NET Framework Version:1.1.4322.2032) throws the
> following exception:
> Exception Details: System.Security.SecurityException: Requested registry
> access is not allowed.
>
> Any ideas?
>
>
>
Author
21 Apr 2005 5:06 PM
Karlo Swart
Hi. I have been reading this thread and I have  the same problem.

I create the event log and source using an admin account and have no problem
doing this. I now try to throw an exception (I use the Exceptionmanager
assembly provided by MS) and use this to write to a custom event log. No
problem in Windows 2000 from any user.

On Win 2003, I can only write to the custom event log using the admin
account. I've located the registery setting for the event log and source and
given full permission to a user other than the systems admin. It fails again.
I am using integrated windows authenticaiton in IIS and windows
authentication and identity  impersonation in my web.config.

Can't see how MS has not released anything to solve the problem on Win 2003.

thanks

Karlo Swart
Author
21 Apr 2005 8:38 PM
chuck rudolph
Karlo, you have to all the posts to see the way around this if you are having
the same issue as me. The key is the "security" log permissions. I will bet
your logname sorts behind "security" in the alphabet. The key for me was
using Regmon to see what was causing the error. If I impersonated an "admin",
it worked for me -- so you might have a different problem.  Best of
luck...Chuck

Show quoteHide quote
"Karlo Swart" wrote:

> Hi. I have been reading this thread and I have  the same problem.
>
> I create the event log and source using an admin account and have no problem
> doing this. I now try to throw an exception (I use the Exceptionmanager
> assembly provided by MS) and use this to write to a custom event log. No
> problem in Windows 2000 from any user.
>
> On Win 2003, I can only write to the custom event log using the admin
> account. I've located the registery setting for the event log and source and
> given full permission to a user other than the systems admin. It fails again.
>  I am using integrated windows authenticaiton in IIS and windows
> authentication and identity  impersonation in my web.config.
>
> Can't see how MS has not released anything to solve the problem on Win 2003.
>
> thanks
>
> Karlo Swart
>
>
>
>
>
>
>