Phương pháp truy vấn thông tin các domain trong cùng Forest.
Xem thêm tại topic cùng tác giả: http://forums.asp.net/p/1015799/1811544.aspx#1811544
public ArrayList GetTrustedDomains() { SearchResultCollection resultCollection = SearchActiveDirectory("container","System"); ArrayList arrList = new ArrayList(); if(resultCollection != null) { foreach (SearchResult sr in resultCollection) { DirectoryEntry entry = sr.GetDirectoryEntry(); foreach(DirectoryEntry newEntry in entry.Children) { if(newEntry.SchemaClassName == "trustedDomain") { arrList.Add(newEntry.Name.Substring(3)); } } } } return arrList; }
private SearchResultCollection SearchActiveDirectory(string categoryType,string nameString) { string filterString; DirectorySearcher directorySearcher = new DirectorySearcher(); filterString = String.Format("(&(objectCategory={0})(name={1}))", categoryType, nameString); directorySearcher.SearchRoot = new DirectoryEntry(Path, UserName, Password, AuthType); directorySearcher.Filter = filterString; SearchResultCollection searchResultCollection = null; try { searchResultCollection = directorySearcher.FindAll(); } catch { } return searchResultCollection; }
Comments
Post a Comment