开发者

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

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}开发者_StackOverflow,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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜