Expected App Pool is not showing. Instead of that Generic App Pool is showing

102 Views Asked by At

I've written code in C# to start and stop the IIS Pool. I've used ServerManager method and trying to user ServerManager().ApplicationPools but it is only showing below five application pools and not the pool I've in my IIS. My IIS version is 10.0.19041.1 . Below is the mentioned code.

IIS Pool I'm getting

"Clr4IntegratedAppPool" "Clr4ClassicAppPool" "Clr2IntegratedAppPool" "Clr2ClassicAppPool" "UnmanagedClassicAppPool"

 private void PerformAction(string action)
    {
       
        // Get selected server and app pools
        string selectedServer = ddlServers.SelectedValue;
        List<string> selectedAppPools = new List<string>();

        foreach (ListItem item in cblAppPools.Items)
        {
            if (item.Selected)
            {
                selectedAppPools.Add(item.Value);
            }
        }

        // Perform start or stop action on selected app pools
        foreach (string appPool in selectedAppPools)
        {
            try
            {
                using (ServerManager serverManager = new ServerManager())
                {
                    Console.WriteLine($"Trying to access App Pool: {appPool}");

                    ApplicationPool selectedAppPool = serverManager.ApplicationPools[appPool];
                    
                    if (action.Equals("start", StringComparison.OrdinalIgnoreCase))
                    {
                        selectedAppPool.Start();
                    }
                    else if (action.Equals("stop", StringComparison.OrdinalIgnoreCase))
                    {
                        selectedAppPool.Stop();
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exception (log it, display it to the user, etc.)
            }
        }

        // Refresh the UI or display a message to the user
        LoadAppPools(selectedServer);
    }
}
1

There are 1 best solutions below

6
samwu On

You can use this code as a reference:

// Writes out the applications and the application pool names 
// associated with the applications under the default Web site.
public void GetApplicationPoolNames()
{
   ServerManager manager = new ServerManager();
   Site defaultSite = manager.Sites["Default Web Site"];

   foreach (Application app in defaultSite.Applications)
   {
       Console.WriteLine(
        "{0} is assigned to the '{1}' application pool.", 
        app.Path, app.ApplicationPoolName);
   }
}