NoBullMan
NoBullMan

Reputation: 2184

Application Pool Status in C#

I am trying to get application pool status from within a web application. Application pool I am interested in is "ABC" but when I check for it by name I get nothing and when I inspect the available pools by name (i.e. manager.ApplicationPools) they show as Clr4ClassicAppPool, Clr4IntegratedAppPool, ... so I never find a match.

This is what I am using

public static int GetAppPoolStatus(string sAppPoolName)
{
    int iRet = -1;
    try
    {
        using (ServerManager manager = new ServerManager())
        {
            ApplicationPool appPool = manager.ApplicationPools.FirstOrDefault(ap => ap.Name == sAppPoolName);

            if (appPool != null)
            {
                //Get the current state of the app pool
                iRet = (int)appPool.State;         // 0: Starting, 1: Started, 2: Stopping, 3: Stopped
            }
            else
            {
            }
        }
    }
    catch (Exception ex)
    { }
    return iRet;
}

Upvotes: 0

Views: 1188

Answers (1)

Lex Li
Lex Li

Reputation: 63173

The GAC version (7.9.0.0) was part of IIS Express, and is resolved by MSBuild when compiling your project if your project file does not explicitly point to %SystemRoot%\system32\inetsrv\Microsoft.Web.Administration.dll.

The ultimate solution (if not to uninstall IIS Express) is to add a reference explicitly to %SystemRoot%\system32\inetsrv\Microsoft.Web.Administration.dll to consume the right metadata at compile time. It has side effects, but still a reliable way. And at runtime, use assembly redirection to stick to version 7.0.0.0.

More tips can be found in this post

Upvotes: 1

Related Questions