6

C#으로 ASP.net을 사용하고 있으며 Active Directory에 대해 거의 생각하지 못했습니다. 아래 단계에 따라 프로그램을 작성하는 작업을 받았습니다.AD의 그룹이 메일 그룹에 있는지 확인하십시오.

ASP.net 응용 프로그램에는 사용자 이름이 부여됩니다.

응용 프로그램은 주어진 사용자 이름으로 사용자의 모든 그룹을 쿼리해야합니다.

그런 다음 응용 프로그램은 이러한 그룹을 메일 그룹과 다른 그룹의 나머지 그룹으로 구성된 두 개의 별도 목록에 표시해야합니다.

이제 모든 그룹에 대한 쿼리가 쉽습니다. 그러나 그룹이 메일 그룹에 있는지 여부를 어떻게 확인할 수 있습니까?

자세한 정보가 제공되지 않았습니다.

확인할 수있는 속성이나 그 밖의 것이 있습니까?

답변

3

Groupe-Type (마지막 줄) 속성에서이 정보를 얻을 수 있습니다.

(0x00000001) : Specifies a group that is created by the system. 
(0x00000002) : Specifies a group with global scope. 
(0x00000004) : Specifies a group with domain local scope. 
(0x00000008) : Specifies a group with universal scope. 
(0x00000010) : Specifies an APP_BASIC group for Windows Server Authorization Manager. 
(0x00000020) : Specifies an APP_QUERY group fir Windows Server Authorization Manager. 
(0x80000000) :Specifies a security group. If this flag is not set, then the group is a distribution group. 

당신은 사용자가 속한 그룹을 retreive하는 this answer 또는 this other one 다른 방법의 botton을에서 찾을 수 있습니다.

here 사용자를 추적하는 방법을 찾을 수 있습니다.

+0

아직 답글을 모르겠다. 왜냐하면 나는 아직 거기에서 무슨 일이 일어나는지 알지 못했기 때문이다 !!! 하지만 지금은 시간이 있기 때문에 자신을 알아 내고 싶기 때문에 무슨 뜻인지는 묻지 않습니다. 그래도 고마워. – PPGoodMan

2

.NET 3.5 이상 버전이므로 System.DirectoryServices.AccountManagement (S.DS.AM) 네임 스페이스를 확인해야합니다. 여기에 대한 모든 읽기 :

// set up domain context 
PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 

// find a user 
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName"); 

if(user != null) 
{ 
    // get all roles for that user 
    var roles = user.GetGroups(); 

    // set up two lists for each type of groups 
    List<GroupPrincipal> securityGroups = new List<GroupPrincipal>(); 
    List<GroupPrincipal> distributionGroups = new List<GroupPrincipal>(); 

    // iterate over groups found 
    foreach (Principal p in roles) 
    { 
     // cast to GroupPrincipal 
     GroupPrincipal gp = (p as GroupPrincipal); 

     if (gp != null) 
     { 
      // check whether it's a security group or a distribution group 
      if (gp.IsSecurityGroup) 
       securityGroups.Add(gp); 
      else 
       distributionGroups.Add(gp); 
     } 
    } 
} 

을 : MSDN docs on System.DirectoryServices.AccountManagement

기본적으로

+0

고마워. 이것은 작동하는 것 같습니다. 두 개의 목록을 제공하지만 관리는 두 목록이 잘못되었다고 주장합니다. 일부 메일 그룹이 보안 그룹 목록에 있음을 의미합니다. 어쩌면 그들이 틀렸을 수도 있습니다. 어쨌든 고맙습니다. 그런데 컴파일 할 때 이상한 오류가 떠 올랐습니다.'암묵적으로 'bool 형식을 변환 할 수 없습니까?' '부울'. 명시 적 변환이 존재합니다 (캐스트가 누락 되었습니까?). bool에 던지면 괜찮 았어. 그러나이 데이터 유형 'bool'은 무엇입니까? ??? 절대 들어 본 적이 없어! – PPGoodMan

+0

@PPGoodMan : ** nullable bool **입니다. NULL, true 또는 false가 될 수 있습니다. –

3

이 코드는 보안 그룹인지 배포 그룹인지에 관계없이 모든 전자 메일 사용 가능 그룹을 검색합니다. (marc_s의 답변에 대한 귀하의 의견을 보았을 때, 저는 이것이 실제로 귀하의 관리자가 찾고있는 것임을 짐작합니다.)

using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain)) 
{ 
    Principal prototype = new GroupPrincipal(ctx); 
    PrincipalSearcher searcher = new PrincipalSearcher(prototype); 
    List<string> groupNames = new List<string>(); 
    PropertyValueCollection email; 

    foreach (var gp in searcher.FindAll()) using (gp) 
    { 
     GroupPrincipal group = gp as GroupPrincipal; 

     using (DirectoryEntry groupEntry = ((DirectoryEntry)group.GetUnderlyingObject()) 
     { 
      email = groupEntry.Properties["mail"]; 
      if (email.Value != null) 
      { 
      groupNames.Add(group.Name); 
      } 
     } 
    } 
}