简体   繁体   中英

How to get applications associated with a application pool in IIS7

I have a virtual directory name. For this virtual directory i have to find out the application pool associated. Once i get the application pool i have to find out all the virtual directories on this application pool.. I am using this code to find out the application pool associated with virtual directory

string AppPoolName = string.Empty;
            ServerManager manager = new ServerManager();
            foreach (Site site in manager.Sites)
            {
                foreach (Application app in site.Applications)
                {
                    string path = app.Path;
                    path = path.Replace("/", " ");
                    path = path.Trim();

                    if (path.ToLower() == VDName.ToLower())
                    {
                        AppPoolName = app.ApplicationPoolName;
                        break;
                    }
                }
            }
using (var serverManager = new ServerManager())
{
    var apps = (from site in serverManager.Sites
                from app in site.Applications
                where app.ApplicationPoolName.Equals("DefaultAppPool")
                select app);
}

I think we have to rerun the function for application pool to get the name for applications associated.

 ServerManager manager = new ServerManager();
        foreach (Site site in manager.Sites)
        {
            foreach (Application app in site.Applications)
            {

                if (app.ApplicationPoolName.ToString() == AppPoolName)
                {
                     string appname = app.Path;
                }
            }
        }

或者新线没有循环方法:

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

May be this link will give you hints to develop your code

Restarting (Recycling) an Application Pool

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM