设置搜索筛选器

通过基于与对象关联的属性(如 objectClass)搜索对象,可使用搜索筛选器筛选特定对象。为此,请使用字符串中包括的所需属性设置筛选器字符串。对于通配符搜索,可以输入要搜索的字符串的任何部分以及一个 *,如 (anr=test*)。将搜索筛选器设置为与 System.DirectoryServices 一起使用时,请遵循 LDAP 筛选器的语法规则。若要指示使用了筛选器,请使用 DirectorySearcher 属性 Filter

有关搜索筛选器的详细信息,请参阅 MSDN Library(网址为 https://go.microsoft.com/fwlink/?LinkID=27252)中的主题“创建查询筛选器”。有关 objectClass 属性的详细信息,请参阅 MSDN Library(网址为 https://go.microsoft.com/fwlink/?LinkID=27252)中的主题 objectClass。

以下代码示例说明如何添加搜索筛选器。

DirectoryEntry entry = new DirectoryEntry("LDAP://CN=users,DC=fabrikam,DC=com");
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectClass=user)(anr=test*))";
SearchResultCollection ResEnt = mySearcher.FindAll();
{
// Handle results.
}
// Handle exceptions.

另请参见

参考

System.DirectoryServices
DirectorySearcher

概念

搜索目录

Send comments about this topic to Microsoft.

版权所有 (C) 2007 Microsoft Corporation。保留所有权利。