我使用c#,DirectoryEntry(System.DirectoryServices)来读取和写入objectClass“inetOrgPerson”的用户。 这很有效,直到我想写属性“labeledURI”或“displayName”。 实际上,我可以写一次,但第二次失败。我认为DirectoryEntry无法从Ldap中读取它们。 我可以提供更多代码,但我希望这个小例子给出一个想法。
PseudoCode:
DirectoryEntry deFound = null;
DirectoryEntry de = new DirectoryEntry(a_strLdapServer + "/" + a_strLdapBasePath, m_strLdapUser, m_strLdapPw, AuthenticationTypes.None);
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.Filter = "(&(objectClass=person) (uid=" + a_strUserName + "))";
//deSearch.PropertiesToLoad.Add("labeledURI");
SearchResultCollection results = deSearch.FindAll();
if (results.Count == 1)
{
deFound = results[0].GetDirectoryEntry();
}
//WORKS ONCE:
deFound.Properties["labeledURI"].Value = "http://www.google.com";
抛出异常: deFound.Properties [“labeledURI”]。值'm_deFound.Properties [“labeledURI”]'抛出类型'System.Runtime.InteropServices.COMException'对象的异常
你知道我做错了吗?
答案 0 :(得分:0)
想出来了!
忘记将ldap://更改为LDAP://或其他蛇油。 该问题隐藏在Windows8(以及Server2012)中。
当你无法访问时 deFound.Properties [ “labeledURI的”] 要么 deFound.Properties [ “显示名”] 你正在使用windows8。,这里是一个Hotfix: http://support.microsoft.com/kb/2802148