Binding 连接到Open LDAP无法与System.DirectoryServices.Protocols绑定

Binding 连接到Open LDAP无法与System.DirectoryServices.Protocols绑定,binding,openldap,directoryservices,Binding,Openldap,Directoryservices,我一直在尝试使用MSDN中的示例代码连接到OpenLDAP(Alex Tcherniakhovski) 我已经在端口636:ssl上进行了尝试,就像在示例代码中一样 并在端口389非ssl上查看是否可以成功 在端口389上尝试时(使用相同的凭据,我可以使用Softerra LDAP浏览器连接到打开的LDAP) 我得到以下错误:可分辨名称包含无效语法 我运行了MicrosoftNetworkMonitor,发现一些不需要的字符被添加到我的绑定请求中,就在我的名字之前。这些字符从未出现在dotne

我一直在尝试使用MSDN中的示例代码连接到OpenLDAP(Alex Tcherniakhovski)

我已经在端口636:ssl上进行了尝试,就像在示例代码中一样

并在端口389非ssl上查看是否可以成功

在端口389上尝试时(使用相同的凭据,我可以使用Softerra LDAP浏览器连接到打开的LDAP)

我得到以下错误:可分辨名称包含无效语法

我运行了MicrosoftNetworkMonitor,发现一些不需要的字符被添加到我的绑定请求中,就在我的名字之前。这些字符从未出现在dotnet解决方案中,但它们是请求的一部分,使请求失败

你有办法摆脱这些吗

我本想展示一张照片,但我不被允许

我的监视器显示BindRequest:Version:3,Name-cn=Manager,dc=

在dotnet中,代码名为“cn=Manager,dc=…”

在端口636上使用与SSL相同的代码会导致以下错误:LDAP服务器不可用

我在尝试从解决方案DirectoryServices.Protocol连接sslbind时遇到相同的错误,从此处下载

谢谢你的帮助

using System.Collections.Generic;
using System.DirectoryServices.Protocols;
using System.Globalization;
using System.Net;
using System.Security;



namespace OpenLDAPNextUID
{
public class LDAPHelper
{
    private readonly LdapConnection ldapConnection;
    private readonly string searchBaseDN;
    private readonly int pageSize;

    public LDAPHelper(
        string searchBaseDN,
        string hostName,
        int portNumber,
        AuthType authType,
        string connectionAccountName,
        SecureString connectionAccountPassword,
        int pageSize)
    {

        var ldapDirectoryIdentifier = new LdapDirectoryIdentifier(
            hostName,
            portNumber,
            true,
            false);

        var networkCredential = new NetworkCredential(
            connectionAccountName,
            connectionAccountPassword);

        ldapConnection = new LdapConnection(
            ldapDirectoryIdentifier,
            networkCredential) 
            {AuthType = authType};

        ldapConnection.SessionOptions.ProtocolVersion = 3;

        this.searchBaseDN = searchBaseDN;
        this.pageSize = pageSize;
    }

    public IEnumerable<SearchResultEntryCollection> PagedSearch(
        string searchFilter,
        string[] attributesToLoad)
    {

        var pagedResults = new List<SearchResultEntryCollection>();

        var searchRequest = new SearchRequest
                (searchBaseDN,
                 searchFilter,
                 SearchScope.Subtree,
                 attributesToLoad);


        var searchOptions = new SearchOptionsControl(SearchOption.DomainScope);
        searchRequest.Controls.Add(searchOptions);

        var pageResultRequestControl = new PageResultRequestControl(pageSize);
        searchRequest.Controls.Add(pageResultRequestControl);

        while (true)
        {
            var searchResponse = (SearchResponse)ldapConnection.SendRequest(searchRequest);
            var pageResponse = (PageResultResponseControl)searchResponse.Controls[0];

            yield return searchResponse.Entries;
            if (pageResponse.Cookie.Length == 0)
                break;

            pageResultRequestControl.Cookie = pageResponse.Cookie;
        }


    }
}
}




namespace OpenLDAP
{
    class Program
    {
        static void Main(string[] args)
        {
            var password = new[]{'P','a','s','s','w','@','r','d'};
            var secureString = new SecureString();
            foreach (var character in password)
                secureString.AppendChar(character);

            var baseOfSearch = "dc=fabrikam,dc=com";
            var ldapHost = "ubuntu.fabrikam.com";
            var ldapPort = 636; //SSL
            var ldapPort = 389; //not SSL
            var connectAsDN = "cn=admin,dc=fabrikam,dc=com";
            var pageSize = 1000;

            var openLDAPHelper = new LDAPHelper(
                baseOfSearch,
                ldapHost,
                ldapPort,
                AuthType.Basic, 
                connectAsDN,
                secureString,
                pageSize);

            var searchFilter = "nextUID=*";
            var attributesToLoad = new[] {"nextUID"};
            var pagedSearchResults = openLDAPHelper.PagedSearch(
                searchFilter,
                attributesToLoad);

            foreach (var searchResultEntryCollection in pagedSearchResults)
                foreach (SearchResultEntry searchResultEntry in searchResultEntryCollection)
                    Console.WriteLine(searchResultEntry.Attributes["nextUID"][0]);

            Console.Read();

        }
    }
}
使用System.Collections.Generic;
使用System.DirectoryServices.Protocols;
利用制度全球化;
Net系统;
使用系统安全;
命名空间OpenLDAPNextUID
{
公共类助听器
{
专用只读LdapConnection LdapConnection;
私有只读字符串searchBaseDN;
私有只读int pageSize;
公共图书馆(
字符串searchBaseDN,
字符串主机名,
int端口号,
AuthType AuthType,
字符串connectionAccountName,
SecureString connectionAccountPassword,
内部页面大小)
{
var ldapDirectoryIdentifier=新的ldapDirectoryIdentifier(
主机名,
端口号,
是的,
假);
var networkCredential=新的networkCredential(
connectionAccountName,
connectionAccountPassword);
ldapConnection=新的ldapConnection(
ldapDirectoryIdentifier,
网络证书)
{AuthType=AuthType};
ldapConnection.SessionOptions.ProtocolVersion=3;
this.searchBaseDN=searchBaseDN;
this.pageSize=页面大小;
}
公共IEnumerable PagedSearch(
字符串搜索过滤器,
字符串[]属性(加载)
{
var pagedResults=新列表();
var searchRequest=新的searchRequest
(searchBaseDN,
搜索过滤器,
SearchScope.Subtree,
属性(负载);
var searchOptions=newsearchoptioncontrol(SearchOption.DomainScope);
searchRequest.Controls.Add(searchOptions);
var pageResultRequestControl=新的pageResultRequestControl(pageSize);
searchRequest.Controls.Add(pageResultRequestControl);
while(true)
{
var searchResponse=(searchResponse)ldapConnection.SendRequest(searchRequest);
var pageResponse=(PageResultResponseControl)searchResponse.Controls[0];
返回searchResponse.Entries;
if(pageResponse.Cookie.Length==0)
打破
pageResultRequestControl.Cookie=pageResponse.Cookie;
}
}
}
}
命名空间OpenLDAP
{
班级计划
{
静态void Main(字符串[]参数)
{
var password=new[]{'P','a','s','s','w','@','r','d'};
var secureString=new secureString();
foreach(密码中的var字符)
AppendChar(字符);
var baseOfSearch=“dc=fabrikam,dc=com”;
var ldapHost=“ubuntu.fabrikam.com”;
var ldapPort=636;//SSL
var ldapPort=389;//不是SSL
var connectAsDN=“cn=admin,dc=fabrikam,dc=com”;
var pageSize=1000;
var openLDAPHelper=新的LDAPHelper(
研究的基础,
ldapHost,
阿尔达波特,
AuthType.Basic,
connectAsDN,
安全字符串,
页面大小);
var searchFilter=“nextUID=*”;
var attributesToLoad=new[]{“nextUID”};
var pagedSearchResults=openLDAPHelper.PagedSearch(
搜索过滤器,
属性(负载);
foreach(pagedSearchResults中的var searchResultEntryCollection)
foreach(SearchResultEntry集合中的SearchResultEntry SearchResultEntry)
Console.WriteLine(searchResultEntry.Attributes[“nextUID”][0]);
Console.Read();
}
}
}

+1使您更接近能够附加图像。有人知道在Active Directory中从何处获取密码值吗?