use*_*945 2 c# directoryservices ldap active-directory
我正在使用DirectorySearcher.FindOne()方法。
我Mobile在我的 Active Directory 用户属性中指定了数字。我的搜索过滤器看起来像这样
(&(ObjectClass=User)(mobile=+11111111111))
Run Code Online (Sandbox Code Playgroud)
有了这个过滤器,我就能找到合适的用户。
我还在我的 AD 用户属性中指定了传真号码,但SearchResult不包含传真属性。实际上SearchResult只包含一个属性,但我期望返回所有用户属性,包括传真号码。
我应该修改我的查询以返回传真号码吗?也许需要更改我的 AD 用户或 LDAP 服务器?
使用 时DirectorySearcher,您可以SearchResult使用PropertiesToLoad集合定义将包含哪些属性。如果不指定任何内容,则只会获得可分辨的 LDAP 名称
所以尝试这样的事情:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7797 次 |
| 最近记录: |