OpenLdap C#使用可分辨名称中的转义字符绑定

OpenLdap C#使用可分辨名称中的转义字符绑定,c#,ldap,directoryservices,openldap,C#,Ldap,Directoryservices,Openldap,我有一些正在工作的LDAP代码,其中我们重新绑定到找到的用户,以便使用该用户的专有名称验证该用户。事实上,这就是正在发生的事情: string userDn = @"cn=Feat Studentl+umanroleid=302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=Pe

我有一些正在工作的LDAP代码,其中我们重新绑定到找到的用户,以便使用该用户的专有名称验证该用户。事实上,这就是正在发生的事情:

            string userDn = @"cn=Feat Studentl+umanroleid=302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB";
            string fullPath = @"LDAP://surinam.testsite.ac.uk:636/" + userDn;

            DirectoryEntry authUser = new DirectoryEntry(fullPath, userDn, "mypassword", AuthenticationTypes.None);

            authUser.RefreshCache();
但是,这会在DirectoryEntry.Bind()处导致未知错误80005000

我怀疑问题可能是DN在CN属性中有一个“+”和一个“=”。因此,在发现转义的方法应该是使用\和字符的十六进制值后,我尝试了以下方法:

            string userDn = @"cn=Feat Studentl\2Bumanroleid\3D302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB";
但是我得到了一个错误:

登录失败:未知用户名或错误密码

我假设这是因为现在它对请求感到满意,但由于某种原因,它无法匹配用户DN


是否存在这种情况?

根据我开发LDAP服务的经验,每当您由于凭据无效而导致登录失败时,绑定尝试往往会出现问题。出现此错误是因为DirectoryEntry不分析DN中的转义字符。。。然而,你不应该一开始就这么做

在代码中,将AuthenticationTypes设置为“None”会强制条目根据您提供的DN进行简单绑定。由于您将服务器名称作为路径的一部分,因此我将尝试改用ServerBind auth类型,如下所示:

string LdapPath = ("LDAP://" + ldapUrl + "/" + Domain);

//Build the user and issue the Refresh bind
var dirEntry = new DirectoryEntry
                   {
                       Path = LdapPath,
                       Username = _usernameToVerify,
                       Password = _passwordToVerify,
                       AuthenticationType = AuthenticationTypes.ServerBind
                   };

//This will load any available properties for the user
dirEntry.RefreshCache();
此外,您似乎正在对安全LDAP端口(636)进行此调用,因此请确保还包括AuthenticationTypes.SecureSocketsLayer和ServerBind Mechanism:

AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.SecureSocketsLayer

希望这有帮助

根据我开发LDAP服务的经验,每当您由于无效凭据而导致登录失败时,绑定尝试往往会出现问题。出现此错误是因为DirectoryEntry不分析DN中的转义字符。。。然而,你不应该一开始就这么做

在代码中,将AuthenticationTypes设置为“None”会强制条目根据您提供的DN进行简单绑定。由于您将服务器名称作为路径的一部分,因此我将尝试改用ServerBind auth类型,如下所示:

string LdapPath = ("LDAP://" + ldapUrl + "/" + Domain);

//Build the user and issue the Refresh bind
var dirEntry = new DirectoryEntry
                   {
                       Path = LdapPath,
                       Username = _usernameToVerify,
                       Password = _passwordToVerify,
                       AuthenticationType = AuthenticationTypes.ServerBind
                   };

//This will load any available properties for the user
dirEntry.RefreshCache();
此外,您似乎正在对安全LDAP端口(636)进行此调用,因此请确保还包括AuthenticationTypes.SecureSocketsLayer和ServerBind Mechanism:

AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.SecureSocketsLayer

希望这有帮助

我不得不求助于挖掘一个为一个客户定制的老DLL项目

我设法使它起作用。如果您有带转义字符的DN,则必须参考这些低级目录服务例程。(注意,在现实生活中,DN是通过设置DirectorySearcher并首先执行FindOne,通过初始felxible用户搜索获得的)


我不得不求助于挖掘一个为一个客户定制的老DLL项目

我设法使它起作用。如果您有带转义字符的DN,则必须参考这些低级目录服务例程。(注意,在现实生活中,DN是通过设置DirectorySearcher并首先执行FindOne,通过初始felxible用户搜索获得的)


谢谢格雷戈里。我尝试了你的例子,我相信它会帮助其他人,但对我来说,它仍然给出了80005000内部错误。我已经发布了一个较低级别的DirectoryServices示例,我成功地实现了它。谢谢Gregory。我尝试了你的例子,我相信它会帮助其他人,但对我来说,它仍然给出了80005000内部错误。我已经发布了一个较低级别的DirectoryServices示例,我成功地实现了这个示例。