【问题标题】:c#, DirectoryEntry fails to read "labeledUri" from openLDAPc#,DirectoryEntry 无法从 openLDAP 读取“labeledUri”
【发布时间】:2014-02-26 17:52:22
【问题描述】:

我正在使用 c#、DirectoryEntry (System.DirectoryServices) 来读取和写入 objectClass "inetOrgPerson" 的用户。 这很好用,直到我想写属性“labeledURI”或“displayName”。 实际上,我可以写一次,但第二次失败了。我认为 DirectoryEntry 很难从 Ldap 中读取它们。 我可以提供更多代码,但我希望这个小例子能提供一个想法。

这里是伪代码:

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"].Value 'm_deFound.Properties["labeledURI"]' 引发了类型为 'System.Runtime.InteropServices.COMException' 对象的异常

你知道我做错了吗?

【问题讨论】:

  • 发现从 SearchResult 中读取“labeledURI”值:Byte[] bytes = (Byte[]) results[0].Properties["labeledURI"][0]; string strValue = System.Text.Encoding.UTF8.GetString(bytes);

标签: c# .net ldap openldap


【解决方案1】:

想通了!

忘记将 ldap:// 更改为 LDAP:// 或其他蛇油。 这个问题隐藏在 Windows8(以及 Server2012)中。

当您无法访问时 deFound.Properties["labeledURI"] 或者 deFound.Properties["displayName"] 并且您使用的是 windows8.,那么这里是一个修补程序: http://support.microsoft.com/kb/2802148

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2021-08-27
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多