0
myUserList AppUsers = new myUserList();  
using (PrincipalContext pcxt = new PrincipalContext(ContextType.Domain, domainName)) 
      { 
       UserPrincipal User = new UserPrincipal(pcxt); 
       User.EmailAddress = emailString; 

       PrincipalSearcher srch = new PrincipalSearcher(User); 
       foreach (var principal in srch.FindAll()) 
       { 
        var p = (UserPrincipal)principal; 
        myUserRow User = AppUsers.NewUsersRow(); 
        User.FirstName = p.GivenName; 
        User.LastName = p.Surname; 
        User.Email = p.EmailAddress; 
        AppUsers.AddUsersRow(User); 

       } 
      } 

Active Directory에서 PrincipalContext 클래스를 사용하여 사용자 정보를 검색하는 코드가 위와 유사합니다.검색 방법 PrincipalContext를 사용하여 글로벌 카탈로그 (전체 포리스트)

위에서 볼 수 있듯이 검색 중에 domainName을 전달합니다. 대신이 코드를 수정하여 전체 포리스트 (예 : 글로벌 카탈로그)를 검색하지만 PrincipalContext 클래스를 계속 사용할 수 있습니까?

글로벌 카탈로그 검색을 수행하기 위해 PrincipalContext 클래스를 사용하는 작동 예제를 찾을 수 없습니다.

이 게시물은 How to search for users in Global Catalog within AD forest with multiple trees이지만 본 포스터에서는 PrincipalContext 클래스를 사용하는 솔루션을 찾지 못했음을 알리는 것처럼 보였습니다. 다시 DirectorySearcher로 전환해야했습니다.

전체 포리스트 (글로벌 카탈로그)에서 검색하는 방법을 보여주는 PrincipalContext 클래스 코드 샘플이 있습니까?

답변

0

괜찮습니다. 아래 코드를 변경해야했습니다.

myUserList AppUsers = new myUserList();  
using (PrincipalContext pcxt = new PrincipalContext(ContextType.Domain, "my-global-catalogue-server.subdomain.domain.com:port", "DC=subdomain,DC=domain,DC=com")) 
      { 
       UserPrincipal User = new UserPrincipal(pcxt); 
       User.EmailAddress = emailString; 

       PrincipalSearcher srch = new PrincipalSearcher(User); 
       foreach (var principal in srch.FindAll()) 
       { 
        var p = (UserPrincipal)principal; 
        myUserRow User = AppUsers.NewUsersRow(); 
        User.FirstName = p.GivenName; 
        User.LastName = p.Surname; 
        User.Email = p.EmailAddress; 
        AppUsers.AddUsersRow(User); 

       } 
      }