问题描述
|
基本上,我正在创建一个员工变更请求表单,并希望在列出的选择中加载电子邮件组(用于添加/删除成员资格),我正在Visual C#中工作,并试图创建一个单独的使用目录服务来完成此任务的类。当我将类添加到App_Code文件夹时,它不再能够找到System.DirectoryServices并给我一个错误。我想念什么?
解决方法
如果您使用的是.NET 3.5及更高版本,则应签出“ 0”(S.DS.AM)名称空间。您需要将其作为.NET参考添加到您的项目中。
在这里阅读所有内容:
在.NET Framework 3.5中管理目录安全主体
基本上,您可以定义域上下文并轻松找到AD中的用户和/或组:
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx,\"SomeUserName\");
if(user != null)
{
// do something here....
}
// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx,\"YourGroupNameHere\");
// if found....
if (group != null)
{
// iterate over members
foreach (Principal p in group.GetMembers())
{
Console.WriteLine(\"{0}: {1}\",p.StructuralObjectClass,p.DisplayName);
// do whatever you need to do to those members
}
}
新的S.DS.AM使得与AD中的用户和组玩起来非常容易: