Check the status of an application pool (IIS 6) with C#

我与影子孤独终老i 提交于 2019-12-01 08:11:02

问题


How can I check the status of an IIS6 application pool with C# ? For example, I want to know if it is running or not ! Thank's in advance for your help !


回答1:


http://msdn.microsoft.com/en-us/library/ms524962.aspx

You can do this checking the AppPoolState Property:

 protected void status()
    {
        string appPoolName = "dev.somesite.com";
        string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName;
        int intStatus = 0;
        try
        {
            DirectoryEntry w3svc = new DirectoryEntry(appPoolPath);
            intStatus = (int)w3svc.InvokeGet("AppPoolState");
            switch (intStatus)
            {
                case 2:
                    lblStatus.Text = "Running";
                    break;
                case 4:
                    lblStatus.Text = "Stopped";
                    break;
                default:
                    lblStatus.Text = "Unknown";
                    break;
            }
        }



回答2:


I think you need the services of WMI ( Windows Management Instrumentation)

There are several articles around on how to manage IIS using WMI via vbscript, e.g.

http://learn.iis.net/page.aspx/163/managing-applications-and-application-pools-on-iis-70-with-wmi/

If you take one of those articles you should be able to adapt it to C# easily enough.



来源:https://stackoverflow.com/questions/2478495/check-the-status-of-an-application-pool-iis-6-with-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!