如何使用 Active Directory 电子邮件填充自动完成框?

How to populate autocopmlete box with Active Directory emails?

我正在寻找从活动目录中获取电子邮件列表和电子邮件组的方法。该列表将用于填充自动完成文本框,与 Outlook 中相同。 你们中有人在过去使用 Asp.Net MVC 做过类似的事情吗?

我前段时间在一个项目中做了这个,我认为你需要采取以下几个步骤:

  1. 为您的域创建一个目录条目
  2. 创建目录搜索器并使用过滤器对其进行初始化
  3. 创建搜索 collection 使用上一个过滤器搜索
  4. 重复搜索 collection
  5. 获取当前迭代的属性
  6. 从 属性 collection
  7. 获取您的电子邮件

代码示例:

  DirectoryEntry dir = new DirectoryEntry("LDAP://" + YourDomain, LoginUsername, LoginPassword);
  DirectorySearcher search = new DirectorySearcher(dir);
  search.Filter = "(&(objectClass=user)(objectCategory=person))";
  SearchResultCollection searchResultCollection = search.FindAll();



if (searchResultCollection != null)
{
   for (int i = 0; i < searchResultCollection.Count; i++)
   { 
       SearchResult crt= searchResultCollection[i];
       PropertyCollection properties= crt.GetDirectoryEntry().Properties;

       // get email from properties["email"].Value
   }
}

一些有用的链接:first , second , third