I believe that I have successfully impersonated my own user account while running an ASP.NET page on my local machine.
Using the method described here, I have successfully changed the WindowsIdentity.GetCurrent().Name from ASPNET to my domain account.
I can successfully write to a file on the file system that ONLY my account has permission to access. However when I try to delete a Performance Counter Category, I get Access Denied.
I have auditing on the branch of the registry and its telling me that MyMachine\ASPNET is Failing at Object Access.
Here is the code it is failing on:
if ( PerformanceCounterCategory.Exists ( PerfmonCategory ) )
PerformanceCounterCategory.Delete ( PerfmonCategory );
Its failing on the Delete Call.
(My account is admin and I can run the same code outside an ASP.NET context successfully).
I suspect that this System.Diagnostics namespace call is actually calling some COM process and somehow I am being bounced because of a 2nd hop. Can anyone confirm what might be going on?
Edit: The Exception: Access is denied Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ComponentModel.Win32Exception: Access is denied
Running under full trust.