0
Active Directory에서 특정 사용자를 검색하려고하는데 FindAll 메서드를 사용하고 있습니다. 내가 호출 할 때 오류가 발생했습니다. 이 문제를 어떻게 해결할 수 있습니까? C# FindAll 메서드를 사용하여 Active Directory에서 특정 사용자를 찾을 수 없습니다.
이
내가 점점 오전 예외 : ' 함께 System.Runtime.InteropServices.COMException'유형의처리되지 않은 예외
SearchResultCollection sResults = null;
try
{
//modify this line to include your domain name
string path = "LDAP://microsistemas.com";
//init a directory entry
DirectoryEntry dEntry = new DirectoryEntry(path);
//init a directory searcher
DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
//This line applies a filter to the search specifying a username to search for
//modify this line to specify a user name. if you want to search for all
//users who start with k - set SearchString to "k";
dSearcher.Filter = "(&(objectClass=user))";
//perform search on active directory
sResults = dSearcher.FindAll();
//loop through results of search
foreach (SearchResult searchResult in sResults)
{
if (searchResult.Properties["CN&"][0].ToString() == "Administrator")
{
////loop through the ad properties
//foreach (string propertyKey in
//searchResult.Properties["st"])
//{
//pull the collection of objects with this key name
ResultPropertyValueCollection valueCollection =
searchResult.Properties["manager"];
foreach (Object propertyValue in valueCollection)
{
//loop through the values that have a specific name
//an example of a property that would have multiple
//collections for the same name would be memberof
//Console.WriteLine("Property Name: " + valueCollection..ToString());
Console.WriteLine("Property Value: " + (string)propertyValue.ToString());
//["sAMAccountName"][0].ToString();
}
//}
Console.WriteLine(" ");
}
}
}
catch (InvalidOperationException iOe)
{
//
}
catch (NotSupportedException nSe)
{
//
}
finally
{
// dispose of objects used
if (sResults != null)
sResults.Dispose();
}
Console.ReadLine();
}
당신은'PrincipalContext'을 잘 알고있는 ...? 또한 왜'' "''vs dsearcher.Filter = " (& (objectClass = user))을 사용하여 필터 텍스트를 래핑하지 않는지 "; – MethodMan