Ken Robertson's Blog

Ramblings of a .NET developer

Method of using Reflection to get current executing user? Or, find out which user an application pool runs as?

Is there some way to use reflection to get the name of the user who is currently executing as?  Or if that isn't possible, is there a way to find out which user the current application pool is running as?

Main reason I ask is as a part of the new nGallery release, we are working on a setup package that takes care of setting up all the necessary permissions for the user.  Sometimes though, people cannot use the installer, such as when they have webhosting.  So we'd also like to include a page in the admin section that checks to make sure all of the permissions are right, and if not, says which directory to give the user access to.  Part of the problem is we can't generalize and say “grant access to ASPNET for IIS5 and Network Service for IIS6”, since it is possible the webhost has the user in a special application pool that might be running as a different user.

Posted: Apr 01 2004, 03:24 PM by qgyen | with 1 comment(s)
Filed under: ,

Comments

Drew Marsh said:

Thread.CurrentPrincipal will get the current .NET security Principal for the current thread. If you want to know the current WindowsIdentity at any given time, use WindowsIdentity::Current. I mention this, because the two are not necessarily the same.

For more on the subject, I suggest researching in the SDK starting under the System.Security.Principal namespace.

HTH,
Drew
# April 1, 2004 9:56 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)