如何使用主体上下文连接到 Active Directory? [英] How to connect to Active Directory with Principal Context?

查看:25
本文介绍了如何使用主体上下文连接到 Active Directory?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这方面已经有一段时间了,我总是得到:

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

System.DirectoryServices.AccountManagement.PrincipalServerDownException

System.DirectoryServices.AccountManagement.PrincipalServerDownException

我认为这意味着我的连接设置(连接字符串)是错误的.

Which I think means my connection setup(connection string) is wrong.

当我在 Active Directory 所在的计算机上的 cmd 上编写dsquery server"时:

When I write "dsquery server" on cmd on the computer where the Active Directory is I get:

"CN=DCESTAGIO,CN=SERVERS,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=estagioit,DC=local"

"CN=DCESTAGIO,CN=SERVERS,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=estagioit,DC=local"

我尝试了以下连接方式:

I've tried the following connecting in the following ways:

1:

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

2:

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

3:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "192.168.56.101/CN=DCESTAGIO,DC=estagioit,DC=local");

4:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "192.168.56.101/CN=DCESTAGIO,CN=SERVERS,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=estagioit,DC=local");

5:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "LDAP://192.168.56.101/CN=Users,DC=estagioit,DC=local");

还有其他一些方式...

And some other ways...

关于出了什么问题以及如何使这种连接正常工作的任何想法?

Any ideas on what's wrong and how I can make this connection work?

PS:IP 是正确的,因为我已经用它来 ping 并且它正在工作.

PS: The ip is correct seen as I've used it to ping and it's working.

PPS:如果你有任何建议,我真的,真的需要尽快让它工作.

PPS: I really, really need this working ASAP if you have any suggestions at all they're all welcome.

推荐答案

如果您查看 PrincipalContext 构造函数的文档,应该很清楚:

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

public PrincipalContext(ContextType contextType, string name)

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

所以你基本上需要:

  • 您的上下文类型(此处:ContextType.Domain)
  • 域名(仅尝试使用Netbios"名称,例如YOURDOMAIN" - 或为默认"域保留 NULL)
  • 可选的容器(作为 LDAP 路径 - 专有"名称、完整路径但没有任何 LDAP:// 前缀)

所以尝试这样的事情:

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

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

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

PrincipalContext thisPrincipalContext = 
    new PrincipalContext(ContextType.Domain, null, "CN=Users,DC=estagioit,DC=local");

这篇关于如何使用主体上下文连接到 Active Directory?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆