[英]How can I use Directory Services in my Web Form?
基本上,我正在创建一个员工变更请求表单,并希望在列出的选择中加载电子邮件组(用于添加/删除成员资格),我正在Visual C#中工作,并试图创建一个单独的使用目录服务来完成此任务的类。 当我将类添加到App_Code文件夹时,它不再能够找到System.DirectoryServices并给我一个错误。 我想念什么?
如果您使用的是.NET 3.5及更高版本,则应签出System.DirectoryServices.AccountManagement
(S.DS.AM)命名空间。 您需要将其作为.NET参考添加到您的项目中。
在这里阅读所有内容:
基本上,您可以定义域上下文并轻松找到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中的用户和组玩起来非常容易:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.