How to connect to Active Directory with Principal Context?(如何使用主体上下文连接到 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用主体上下文连接到 Active Directory?
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
