7

私は C# で ASP.net を使用していますが、Active Directory についてほとんど知りません。以下の手順でプログラムを作成するタスクが与えられました。

ASP.net アプリケーションには、ユーザーのユーザー名が与えられます。

アプリケーションは、指定されたユーザー名を持つユーザーのすべてのグループを照会する必要があります。

次に、アプリケーションはこれらのグループを 2 つの個別のリストに表示する必要があります。1 つは配布グループで構成され、もう 1 つは残りのグループで構成されます。

これで、すべてのグループのクエリが簡単になりました。しかし、グループが配布グループに含まれているかどうかを確認するにはどうすればよいですか?

これ以上の情報は提供されていません。

属性または確認できるものはありますか?

4

3 に答える 3

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.

この回答またはこの他の1つのボタンの下部に、ユーザーが属するグループを取得するためのさまざまな方法があります。

ここで、ユーザーを取得する方法を見つけることができます。

于 2011-11-01T05:47:51.360 に答える
3

.NET 3.5以降を使用しているため、System.DirectoryServices.AccountManagement(S.DS.AM)名前空間を確認する必要があります。ここでそれについてすべて読んでください:

基本的に、ドメインコンテキストを定義して、AD内のユーザーやグループを簡単に見つけることができます。

// 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);
       }
    }
}

新しいS.DS.AMを使用すると、ADのユーザーやグループを簡単に操作できます。

于 2011-11-01T06:02:54.600 に答える
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);
          }
        }
    }
}
于 2013-03-19T16:39:33.703 に答える