关于C#中控制IIS的问题(DirectorySearcher)

来源:互联网 发布:js 自定义window方法 编辑:程序博客网 时间:2024/06/03 19:24

DirectoryEntry root = new DirectoryEntry ("IIS://localhost/w3svc","administrator","2040601",AuthenticationTypes.Secure &    AuthenticationTypes.ServerBind);
    DirectorySearcher searcher = new DirectorySearcher(root);

程序跳框说提供程序不支持搜索操作,因此无法搜索IIS://localhost/w3svc

System.DirectoryServices 命名空間 (Namespace) 提供從 Managed 程式碼對 Active Directory 的簡易存取。命名空間包含兩個元件類別: DirectoryEntry 和 DirectorySearcher ,它們使用 Active Directory Services Interface (ADSI) 技術。ADSI 是一組 Microsoft 提供的介面,做為與多種網路提供者一起使用的彈性工具。不管網路的大小為何,ADSI 能夠減輕系統管理員尋找並管理網路資源的負擔。

這個命名空間中的類別可以搭配任何 Active Directory 服務提供者使用。目前的提供者有 Internet Information Services (IIS)、Lightweight Directory Access Protocol (LDAP)、Novell NetWare Directory Service (NDS) 和 WinNT。

ADSI 是 Microsoft Active Directory 的程式設計介面,使用單一介面就可以讓您的應用程式與網路上多種目錄進行互動。使用 ADSI,您可以建立可執行一般工作的應用程式,例如備份資料庫、存取印表機、和管理使用者帳戶。

它假設您在使用這些類別之前已對 Active Directory 有一般性瞭解。如需 Active Directory 的詳細資訊,請參閱 Active Directory 物件簡介 、 Active Directory 技術背景 和 MSDN Library (msdn.microsoft.com) 中的 Active Directory 主題:

Active Directory Programmers Guide
Active Directory Service Interfaces
Lightweight Directory Access Protocol API
ADSI System Providers
WinNT Binding String
Binding
IADsOpenDSObject::OpenDSObject
Active Directory 是樹狀結構。樹狀結構中的每一個節點都包含一組屬性。使用這個命名空間來往返、搜尋和修改樹狀結構,以及讀取與寫入節點的屬性。

DirectoryEntry 類別會將 Active Directory 階層架構中的節點或物件封裝。使用這個類別以繫結至物件、讀取屬性 (Property) 和更新屬性 (Attribute)。協同 Helper 類別, DirectoryEntry 提供存留週期管理與巡覽方法的支援,包括建立、刪除、重新命名、移除子節點和列舉子系等。

使用 DirectorySearcher 類別來執行對 Active Directory 階層架構的查詢。LDAP 是唯一提供 Active Directory Service Interfaces (ADSI) 提供者 (支援搜尋) 的系統。

透過 DirectorySearcher 搜尋 Active Directory 階層架構可傳回 SearchResult 的執行個體 (Instance),其包含在 SearchResultCollection 類別的執行個體中。