AD 与 LDAP 连接错误

AD with LDAP connection error

我正在尝试使用 .net 应用程序,但该应用程序无法在我的本地网络中找到服务器。

我正在使用具有以下设置的 LdapExploreTool 2:

the base DN is "DC=exago,DC=local", the Ip address "192.168.1.250" and the server name "exago.local"

连接成功,结果如下:
输入值:
检查代码,我在 "Bind to the native AdsObject to force authentication":

时得到异常

"The specified domain either does not exist or could not be contacted."

  public bool IsAuthenticated(string domain, string ldapPath, string username, string pwd, string userToValidate)
    {
        string domainAndUsername = domain + @"\" + username;

        if (string.IsNullOrEmpty(ldapPath))
            SetLdapPath(domain);
        else
            _path = ldapPath;
        App.Services.Log.LogUtils.WriteLog(Log.LogLevel.INFO, "IsAuthenticated_DirectoryEntry:" + _path + "," + domainAndUsername + "," + pwd);
        DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

        //check if domain is valid
        int domainId = AppDomains.GetDomainIdByName(domain);
        if (domainId == int.MinValue)
        {
            return false;
        }

        AppDomains d = AppDomains.GetRecord(domainId);
        List<AppDomainQueries> lQueries = new List<AppDomainQueries>(AppDomainQueries.GetArray());
        lQueries = lQueries.FindAll(delegate(AppDomainQueries dq) { return dq.DomainId == domainId && dq.Status == 'A'; });

        string queryString = string.Empty;
        try
        {
            // Bind to the native AdsObject to force authentication.
            Object obj = entry.NativeObject;

            DirectorySearcher search = new DirectorySearcher(entry);

            string ldapAndQuerie = string.Empty;

            //base account search
            queryString = "(SAMAccountName=" + userToValidate + ")";


            if (username != userToValidate)
            {
                if (lQueries.Count == 1)
                    ldapAndQuerie = lQueries.FirstOrDefault().QueryString;

                if ((ldapAndQuerie != string.Empty) && (ldapAndQuerie != "*") && (ldapAndQuerie != "(objectClass = user)"))
                    queryString = "(&(SAMAccountName=" + userToValidate + ")" + ldapAndQuerie + ")";
            }

            search.Filter = queryString;

            App.Services.Log.LogUtils.WriteLog(Log.LogLevel.INFO, "LDAP=" + queryString);


            search.PropertiesToLoad.Add("cn");
            SearchResult result = search.FindOne();
            if (null == result)
            {
                return false;
            }
            // Update the new path to the user in the directory
            _path = result.Path;
            _filterAttribute = (String)result.Properties["cn"][0];
        }
        catch (Exception ex)
        {
            App.Services.Log.LogUtils.WriteLog(Log.LogLevel.ERROR, "App.Services.Core.LdapAuthentication.IsAuthenticated() Exception - (LDAP=" + queryString + ")" + ex.Message, ex);
            return false;
        }
        return true;
    }

如何建立连接?

问题是 LDAP 连接字符串, 它似乎错过了网络中的实际位置(IP + 端口)。

LDAP://192.168.1.250:389/DC=exago,DC=local