.NET의 버전은 무엇입니까 ??
.NET 3.5를 사용하는 경우 Active Directory 인터페이스가 어떻게 바뀌 었는지이 우수한 MSDN article을 참조하십시오. 당신이 .NET 3.5 경우
, 당신이 쓸 수 :
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN");
Principal myObject = Principal.FindByIdentity(ctx, "your name value");
을 일반적으로, 당신은 단지 사용자 이름을 전달해야 할 것이다 -이 아닌 전체 도메인 \ 사용자 이름 - 백 슬래시 이후 부분을 끈.
이 "교장은"이제 중 하나가 UserPrincipal
또는 GroupPrincipal
이다 (또는 원금의 다른 유형의, 예를 들어, ComputerPrincipal
이 수) :
if(myObject is UserPrincipal)
{
// you have a user
}
else if(myObject is GroupPrincipal)
{
// you have a group
}
당신은 거기에서 갈 수 있습니다.
는 .NET 1.x에서에 있다면// 3.0 2.0, 당신은 DirectorySearcher
를 생성하고 개체를 검색하는 약간 더 복잡 절차를 사용해야 할 것 :
// create root DirectoryEntry for your search
DirectoryEntry deRoot = new DirectoryEntry("LDAP://dc=YourCompany,dc=com");
// create searcher
DirectorySearcher ds = new DirectorySearcher(deRoot);
ds.SearchScope = SearchScope.Subtree;
// define LDAP filter - all you can specify is the "anr" (ambiguous name
// resolution) attribute of the object you're looking for
ds.Filter = string.Format("(anr={0})", "YourNameValue");
// define properties you want in search result(s)
ds.PropertiesToLoad.Add("objectCategory");
ds.PropertiesToLoad.Add("displayName");
// search
SearchResult sr = ds.FindOne();
// check if we get anything back, and if we can check the "objectCategory"
// property in the search result
if (sr != null)
{
if(sr.Properties["objectCategory"] != null)
{
// objectType will be "Person" or "Group" (or something else entirely)
string objectType = sr.Properties["objectCategory"][0].ToString();
}
}
을 Marc
답장을 보내 주셔서 감사합니다. – ddou