views:

141

answers:

1

Hi there

My web application is a product which has to deploy to a variety of web servers. Is there a way to determine the account name that the .Net worker process account is using at runtime?

Using .Net 3.5, C#

Thanks in advance

-Pete

+3  A: 

Have you tried System.Environment.UserName ?

Edit:

You're right, the environment username doesn't seem to work. Here's something else you could try, which I've tested on IIS 7 / Windows Vista:

System.Security.Principal.WindowsIdentity.GetCurrent().Name

Returns "NT AUTHORITY\NETWORK SERVICE" for me since my default app pool runs as network service.

Michael Petito
Thanks Michael;In my system (Win 7, IIS 7.5) that's giving me the app pool name. "DefaultAppPool" But we need this name to direct the user as to which user should be given write permission on a file. The app pool name would not help in this case.
pmawhinney