如何解决如何在我的Web窗体中使用目录服务?
| 基本上,我正在创建一个员工变更请求表单,并希望在列出的选择中加载电子邮件组(用于添加/删除成员资格),我正在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中的用户和组玩起来非常容易:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。