0

I have a web api controller, and I need to get the identity of the app pool which hosts the web application in IIS.

I have tried

string threadName = System.Threading.Thread.CurrentPrincipal.Identity.Name;
string username = this.User.Identity.Name;

But both are null. I want the name which runs the w3wp.exe such as IIS APPPOOL\DefaultAppPool or NETWORKSERVICE or whatever the app pool is configured to run as.

Tried both with authentication=none which is the default when creating a new Wep Api project in VS2013 and also tried with Forms auth, but no luck.

mikanyg
  • 393
  • 4
  • 15
  • Use the IIS API to get it, because user.Identity.Name and thread principal will be null unless someone is logged into the session or if the identity is explicitly set and Load User Profile is true on the app pool. https://msdn.microsoft.com/en-us/library/aa347649%28v=vs.90%29.aspx – Ryan Mann Feb 06 '15 at 00:52
  • possible duplicate of [Get the Application Pool Identity programmatically](http://stackoverflow.com/questions/10101162/get-the-application-pool-identity-programmatically) – Roger Lipscombe Feb 06 '15 at 08:10

1 Answers1

0

Found the answer on this thread:Get the Application Pool Identity programmatically

I was looking for

string appPoolName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Community
  • 1
  • 1
mikanyg
  • 393
  • 4
  • 15