Current application pool name

1

I am trying to get the current application pool name of a web application. I googled a lot and I found several ways to do it but none of them seems to work for me This is one of my implementations:

   private static string GetCurrentApplicationPoolId()
    {
        string virtualDirPath = AppDomain.CurrentDomain.FriendlyName;
        virtualDirPath = virtualDirPath.Substring(4);
        int index = virtualDirPath.Length + 1;
        index = virtualDirPath.LastIndexOf("-", index - 1, index - 1);
        index = virtualDirPath.LastIndexOf("-", index - 1, index - 1);
        virtualDirPath = "IIS://localhost/" + virtualDirPath.Remove(index);
        DirectoryEntry virtualDirEntry = new DirectoryEntry(virtualDirPath);
        return virtualDirEntry.Properties["AppPoolId"].Value.ToString();
    }

I get as an error: Unknown error (0x80005000)

c#
asp.net
security
iis
application-pool
asked on Stack Overflow May 28, 2014 by user3679520 • edited Jun 7, 2014 by BenMorel

2 Answers

0

Control panel - program features - turn on off - look for IIS 6 compatibily and check everything.

answered on Stack Overflow May 28, 2014 by Robert P
0

If you have the HttpContext in place use this:

 HttpContext.Current.Request.ServerVariables["APP_POOL_ID"]

If not use this:

System.Environment.GetEnvironmentVariable(
  "APP_POOL_ID", 
  EnvironmentVariableTarget.Process);

Source


User contributions licensed under CC BY-SA 3.0