查明 AD 中的组是否属于通讯组?
我正在使用 ASP.net 和 C#,并且对 Active Directory 知之甚少。我收到了按以下步骤编写程序的任务:
为 ASP.net 应用程序提供了用户的用户名。
应用程序应查询具有给定用户名的用户的所有组。
然后,应用程序应将这些组显示在两个单独的列表中,一个列表包含通讯组,另一个列表包含其余组。
现在,查询所有组就很容易了。但是如何检查该组是否在通讯组中呢?
我没有得到更多信息。
有什么属性或者我可以检查的东西吗?
I'm using ASP.net with C# and have a very little idea about Active Directory. I've been given a task to write a program in steps below:
The ASP.net application is given the username of a user.
The application should query all the groups of the user with the given username.
Then the application should display these groups in two separate lists one consisting of the distribution groups and in other list, the rest of the groups.
Now, the querying for all the groups is easy. But how can I check whether the group is in distribution group or not?
I have not been given more information.
Any attribute or something I can check?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(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.
您可以在此答案中找到或在 这另一个不同检索用户所属组的方法。
您可以在此处找到如何检索用户。
由于您使用的是 .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 中使用用户和组变得非常容易!
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
此代码将检索所有启用电子邮件的组,无论它是安全组还是通讯组。 (看到您对 marc_s 答案的评论后,我猜这实际上就是您的经理正在寻找的)。
This code will retrieve all your email enabled groups, regardless of whether it is a security or distribution group. (Having seen your comment to marc_s's answer, I'm guessing this is actually what your managers are looking for).