在IIS中枚举应用程序池

6

我想知道是否有一种方法可以在本地IIS服务器上使用ASP.net 3.5列举应用程序池的集合(不是给定池中的应用程序,而是池本身),而不使用WMI。如果有的话,能否提供一个链接或示例来说明如何完成此操作?

(我忘记添加了IIS版本是6.0.)

2个回答

8
另一种可能有帮助的方法。
using System.IO;
using Microsoft.Web.Administration;

namespace AppPoolEnum
{
    class Program
    {
        static void Main(string[] args)
        {   
                foreach (var appPool in  new ServerManager().ApplicationPools)
                {
                    Console.WriteLine(appPool.Name);
                }
        }
    }
}

3
这可以在NuGet包Microsoft.Web.Administration中找到。 - pilotcam
抱歉,该代码无法显示当前服务器的所有应用程序池。 - enb141

5
这应该可以帮助你:

这将有助于:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;

namespace AppPoolEnum
{
    class Program
    {
        static void Main(string[] args)
        {
            DirectoryEntries appPools = 
                new DirectoryEntry("IIS://localhost/W3SVC/AppPools").Children;

            foreach (DirectoryEntry appPool in appPools)
            {
                Console.WriteLine(appPool.Name);
            }
        }
    }
}

我还要补充一点,这在部分信任模式下不起作用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接