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

做~自己de王妃 提交于 2019-12-11 14:14:55

问题


I'm trying to use the DomainServices class to retrieve a list of OU's from my Active Directory.

Here's my code:

public List<OrganizationalUnit> FindOrganizationalUnits(string domainName, string domainExtension, string parentOrganizationUnit)
{
    string tmpDirectory = String.Format("LDAP://ou={0},dc={1},dc={2}", 
                                            parentOrganizationUnit,
                                            domainName,
                                            domainExtension
    );

    DirectoryEntry directory = new DirectoryEntry(tmpDirectory);

    DirectorySearcher searcher = new DirectorySearcher(directory);
    searcher.Filter = "(objectClass=organizationalUnit)";
    searcher.SearchScope = SearchScope.Subtree;
    searcher.PropertiesToLoad.Add("displayName");

    var organizationalUnits = new List<OrganizationalUnit>();
    foreach (SearchResult result in searcher.FindAll())
    {
        //I just create and return a new OrganizationalUnit object based on the SearchResult result.
        organizationalUnits.Add(new OrganizationalUnit(result));
    }

    return organizationalUnits;
}

Is there some configuration I have to set on my server end to let me use DirectoryServices to query it's AD objects?

Thanks for the help.


回答1:


What type of app are you running this code from? AD queries have to be made from an authenticated resource. You can either use the current credentials of the user, or pass in a new name/password.

Services usually don't have any issue, running under LocalSystem, but if this is a web app running under IIS standard permissions, it might cause an issue.

Try adding some credentials where you're instantiating your DirectoryEntry class.



来源:https://stackoverflow.com/questions/5359151/the-specified-domain-either-does-not-exist-or-could-not-be-contacted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!