2009-09-09 103 views
5

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

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

回答

4

这应有助于:

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); 
      } 
     } 
    } 
} 

我还要补充,这将不会在部分信任的工作。

2

另一种可能有用的方法。

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); 
       } 
     } 
    } 
} 
+0

这可以在nuget软件包'Microsoft.Web.Administration' – pilotcam 2017-02-09 16:09:32