我在这方面已经有一段时间了,我总是得到:
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
)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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!