How to connect to Active Directory with Principal Context?

后端 未结 1 378
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 18:54

I\'ve been at this for a while and I\'m always getting:

System.DirectoryServices.AccountManagement.PrincipalServerDownException

相关标签:
1条回答
  • 2021-01-01 19:23

    If you look at the documentation for the PrincipalContext constructors, it should be quite clear:

    public PrincipalContext(ContextType contextType, string name)
    

    or

    public PrincipalContext(ContextType contextType, string name, string container)
    

    So you basically need:

    • your context type (here: ContextType.Domain)
    • the domain name (try just the "Netbios" name, e.g. "YOURDOMAIN" - or leave NULL for "default" domain)
    • optionally a container (as an LDAP path - a "distinguished" name, full path but without any LDAP:// prefix)

    So try something like this:

    PrincipalContext thisPrincipalContext = 
        new PrincipalContext(ContextType.Domain, "ESTAGIOIT");
    

    or

    PrincipalContext thisPrincipalContext = 
        new PrincipalContext(ContextType.Domain, null);  // default domain
    

    or

    PrincipalContext thisPrincipalContext = 
        new PrincipalContext(ContextType.Domain, "ESTAGIOIT", "DC=estagioit,DC=local");
    

    or

    PrincipalContext thisPrincipalContext = 
        new PrincipalContext(ContextType.Domain, null, "CN=Users,DC=estagioit,DC=local");
    
    0 讨论(0)
提交回复
热议问题