2011-03-16 3 views
0

C#의 특정 사용자에 대해 LDAP Active Directory의 사용자 그룹을 확인해야합니다. 이 사용자 이름을 메서드에 전달한다는 것은 해당 사용자가 속한 그룹의 목록을 반환한다는 것을 의미합니다. 이걸 좀 도와주세요. Im 많이 검색하지만, 매번 새로운 오류가 발생합니다.특정 사용자의 Usergroup에 대한 LDAP 쿼리

LDAP 경로 : 192.168.1.4는

도메인 이름 : 아르 슬란은

사용자 이름 : ArslanP는

암호 : testad

+0

문제가있는 코드를 게시하면 도움이 될 수 있습니다. – SGarratt

답변

1

당신이 .NET 3.5 및 최대에있어 있기 때문에, 당신은 System.DirectoryServices.AccountManagement (S.DS.AM) 네임 스페이스를 확인해야합니다. AD에서 사용자 및/또는 그룹을 쉽게 찾을

Managing Directory Security Principals in the .NET Framework 3.5

기본적으로

이 어셈블리 System.DirectoryServices.AccountManagement에 대한 참조를 추가 한 다음 도메인 컨텍스트를 정의하고 : 여기에 대한 모든 읽기

using System.DirectoryServices.AccountManagement; 

public List<GroupPrincipal> GetGroupsForUser(string username) 
{ 
    List<GroupPrincipal> result = new List<GroupPrincipal>(); 

    // set up domain context - if you do a lot of requests, you might 
    // want to create that outside the method and pass it in as a parameter 
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 

    // find user by name 
    UserPrincipal user = UserPrincipal.FindByIdentity(username); 

    // get the user's groups 
    if(user != null) 
    { 
    foreach(GroupPrincipal gp in user.GetAuthorizationGroups()) 
    { 
     result.Add(gp); 
    }  
    } 

    return result; 
} 

새로운 S.DS.AM을 사용하면 광고에서 사용자 및 그룹과 놀아 볼 수 있습니다.

관련 문제