2013-10-23 3 views
0

DirectoryEntry 클래스를 사용하여 localhost IIS 관리자 6에서 모든 웹 사이트를 가져 오는 중, 각 웹 응용 프로그램의 로컬 경로를 가져오고 싶지만 가져 오는 방법을 모르겠다. 어쨌든 있습니까? 내가 디렉토리 항목의 모든 속성을 열거 할 수 있습니까?디렉토리 항목 개체에서 모든 속성 이름과 값 가져 오기

DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC"); 

foreach (DirectoryEntry e in root.Children) 
{ 
    if (e.SchemaClassName == "IIsWebServer") 
    { 
     Console.WriteLine(e.Properties["ServerComment"].Value.ToString()); 
     // how can I enumerate all properties and there values here ? 
     // maybe write to a xml document to find the local path property 

답변

1

다음 코드를 사용하면 필요한 것을 찾을 수 있습니다. 다른 질문이 단지 같은 접근법을 사용하는 경우. 이 코드는 IIS6에서 작동합니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

// to add it from %windir%\System32\InetSrv\Microsoft.Web.Administration.dll 
using Microsoft.Web.Administration; 

namespace IIS_7 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      using (ServerManager serverManager = new ServerManager()) 
      { 
       foreach (var site in serverManager.Sites) 
       { 

        Console.WriteLine(String.Format("Site: {0}", site.Name)); 

        foreach (var app in site.Applications) 
        { 
         var virtualRoot = app.VirtualDirectories.Where(v => v.Path == "/").Single(); 

         Console.WriteLine(String.Format("\t\t{0} \t\t{1}", app.Path, virtualRoot.PhysicalPath)); 
        } 
       } 
      } 
     } 
    } 
} 
: IIS 7에 관해서

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 



using System.DirectoryServices; 

namespace IIS_6 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC"); 
      string VirDirSchemaName = "IIsWebVirtualDir"; 

      foreach (DirectoryEntry e in root.Children) 
      { 

       foreach (DirectoryEntry folderRoot in e.Children) 
       { 
        foreach (DirectoryEntry virtualDirectory in folderRoot.Children) 
        { 
         if (VirDirSchemaName == virtualDirectory.SchemaClassName) 
         { 
          Console.WriteLine(String.Format("\t\t{0} \t\t{1}", virtualDirectory.Name, virtualDirectory.Properties["Path"].Value)); 
         } 
        } 
       } 
      } 
     } 
    } 
} 

는이 코드를 썼다