2

Is there a way to programmatically determine which application pool a service application is running on? I haven't really found much on this so far. Any help is appreciated!

athom
  • 1,257
  • 4
  • 13
  • 30

3 Answers3

1

IIS assigns the application to an app pool. I don't know of a way to change the app pool programmatically or through configuration.

EDIT: I take that back it looks like this is possible, this article may help you: Setup IIS programmaticaly

cobolstinks
  • 6,801
  • 16
  • 68
  • 97
1

This is a sample code for IIS6, I am not sure though it will work for Sharepoint or another version of IIS...

public string GetAppPoolName() {
    string AppPath = Context.Request.ServerVariables["APPL_MD_PATH"];

    AppPath = AppPath.Replace("/LM/", "IIS://localhost/");
    DirectoryEntry root = new DirectoryEntry(AppPath);
    if ((root == null)) {
        return " no object got";
    }
    string AppPoolId = (string)root.Properties["AppPoolId"].Value;
    return AppPoolId;
}

Copied from How to detect what Application Pool I am currently running under? (IIS6)

Community
  • 1
  • 1
aKzenT
  • 7,775
  • 2
  • 36
  • 65
0

Someone supplied me with a SharePoint specific answer here, but thanks everyone for your input. The following code is how I got the application pool:

foreach (SPService service in SPFarm.Local.Services)
{
    if (service.Name.Equals("ServiceName"))
    {
        foreach (SPServiceApplication serviceApp in service.Applications)
        {
            SPIisWebServiceApplication webServiceApp = (SPIisWebServiceApplication) serviceApp;
            SPIisWebServiceApplicationPool appPool = webServiceApp.ApplicationPool;
        }
    }
}
Community
  • 1
  • 1
athom
  • 1,257
  • 4
  • 13
  • 30