2

I use the codes below to get the ApplicationPools and sites ,but how can i know the site is in which applicationpool

        var serverManager = ServerManager.OpenRemote("127.0.0.1");
        var appPools = serverManager.ApplicationPools;
        var site= serverManager.Sites;
        Console.WriteLine("Sites:");
        foreach (var st in site)
            Console.WriteLine(st.Name);
        Console.WriteLine( );


        Console.WriteLine("Pools:");
        foreach (var ap in appPools)
            Console.WriteLine(ap.Name);
        Console.Read();
Sasayaku
  • 69
  • 5
  • Possible duplicate of http://stackoverflow.com/questions/7607175/how-to-get-applications-associated-with-a-application-pool-in-iis7 – Amit Feb 02 '15 at 05:52
  • @Amit ,thanks. It's right , maybe i use the different keys to search, it's not appeared just now. – Sasayaku Feb 02 '15 at 06:27

2 Answers2

2

With ApplicationPoolName you can know the name of the application pool that the application is assigned to See Here

to display the app pool name on your web page you can simply use the below snippet code.

 <% Request.ServerVariables("APP_POOL_ID") %>

And you can also get PoolName as following below:

string appPoolName = HttpContext.Current.Request.ServerVariables["APP_POOL_ID"];
if (String.IsNullOrEmpty(appPoolName))
    appPoolName = Environment.GetEnvironmentVariable("APP_POOL_ID", EnvironmentVariableTarget.Process);

To get IIS Server Variables take a look at this.

This is also can be useful for programmatically listing, getting and setting Application Pools.

Aria
  • 3,724
  • 1
  • 20
  • 51
0

A site specifies the default application pool for applications. Each application can be changed to use another application pool if the default is inadequate.Use the following to obtain the site's and application's application pool:

var sites = new ServerManager().Sites;
foreach (var site in sites) 
{
   Console.WriteLine(site.ApplicationDefaults.ApplicationPoolName);

    foreach (var application in site.Applications)
    {
       Console.WriteLine(application.ApplicationPoolName);
    }
}