[英]Getting AD information in ASP.NET in C#
我是C#中的ASP.NET新手。
目前我正在摆弄一个简单的网络应用程序,试图通过用户名搜索并显示AD名字和姓氏到表格。 绝对没有成功。
由于我是新手,所以任何人都可以告诉我如何,或指向我如何这样做的教程/文章。
基本上这就是我的归宿。
DirectoryEntry myLDAPConnection = new DirectoryEntry("LDAP://company.com");
DirectorySearcher dSearch = new DirectorySearcher(myLDAPConnection);
我知道我需要用我的dSearch对象做一些事情来过滤返回的内容。 但我不知道该怎么做。
谢谢
如果您使用的是.NET 3.5及更高版本,则应该查看System.DirectoryServices.AccountManagement
(S.DS.AM)命名空间。 在这里阅读所有相关内容:
基本上,您可以定义域上下文并轻松查找AD中的用户和/或组:
// set up domain context
using (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.