How to connect to Active Directory with Principal Context?

余生长醉 提交于 2019-11-30 17:49:36

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