2

我正在使用DirectorySearcher.FindOne()方法。

Mobile在我的 Active Directory 用户属性中指定了数字。我的搜索过滤器看起来像这样

(&(ObjectClass=User)(mobile=+11111111111))

使用此过滤器,我可以获得合适的用户。

我还在我的 AD 用户属性中指定了传真号码,但SearchResult不包含传真属性。实际上SearchResult只包含一个属性,但我希望返回所有用户属性,包括传真号码。

我应该修改我的查询以返回传真号码吗?也许需要更改我的 AD 用户或 LDAP 服务器?

4

1 回答 1

5

使用 时,您可以使用集合DirectorySearcher定义将包含哪些属性。如果不指定任何内容,则只会获得可分辨的 LDAP 名称SearchResultPropertiesToLoad

所以尝试这样的事情:

DirectoryEntry root = new DirectoryEntry("LDAP://-your-base-LDAP-path-here-");

DirectorySearcher searcher = new DirectorySearcher(root);
searcher.Filter = "(&(ObjectClass=User)(mobile=+11111111111))";

// DEFINE what properties you need !
searcher.PropertiesToLoad.Add("Mobile");
searcher.PropertiesToLoad.Add("Fax");

SearchResult result = searcher.FindOne();

if (result != null)
{
   if (result.Properties["Fax"] != null)
   {
      string fax = result.Properties["Fax"][0].ToString();
   }

   if (result.Properties["Mobile"] != null)
   {
      string mobile = result.Properties["Mobile"][0].ToString();
   }
}
于 2013-08-08T16:01:55.057 回答