[英]Getting AD information in ASP.NET in C#
I am new to ASP.NET in C#. 我是C#中的ASP.NET新手。
Currently I am just fiddling around with a simple web app trying to search by a username and display the AD First and Last name to a table. 目前我正在摆弄一个简单的网络应用程序,试图通过用户名搜索并显示AD名字和姓氏到表格。 With absolutely no success.
绝对没有成功。
Since I am so new to this could anybody show me how, or point me to a tutorial/article on how to do so. 由于我是新手,所以任何人都可以告诉我如何,或指向我如何这样做的教程/文章。
Basically this is what I have come down to. 基本上这就是我的归宿。
DirectoryEntry myLDAPConnection = new DirectoryEntry("LDAP://company.com");
DirectorySearcher dSearch = new DirectorySearcher(myLDAPConnection);
I understand I need to do something with my dSearch object to filter what is returned. 我知道我需要用我的dSearch对象做一些事情来过滤返回的内容。 But I have no clue what to do beyond this.
但我不知道该怎么做。
Thanks 谢谢
If you're on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement
(S.DS.AM) namespace. 如果您使用的是.NET 3.5及更高版本,则应该查看
System.DirectoryServices.AccountManagement
(S.DS.AM)命名空间。 Read all about it here: 在这里阅读所有相关内容:
Basically, you can define a domain context and easily find users and/or groups in AD: 基本上,您可以定义域上下文并轻松查找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
}
}
}
The new S.DS.AM makes it really easy to play around with users and groups in AD! 新的S.DS.AM使得在AD中与用户和群组玩游戏变得非常容易!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.