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?
基础教程推荐
- 使用 SED 在 XML 标签之间提取值 2022-01-01
- C# - 将浮点数转换为整数...并根据余数更改整数 2022-01-01
- 从 VB6 迁移到 .NET/.NET Core 的最佳策略或工具 2022-01-01
- 创建属性设置器委托 2022-01-01
- 当键值未知时反序列化 JSON 2022-01-01
- C# - 如何列出发布到 ASPX 页面的变量名称和值 2022-01-01
- 如何使用OpenXML SDK将Excel转换为CSV? 2022-01-01
- 覆盖 Json.Net 中的默认原始类型处理 2022-01-01
- Page.OnAppearing 中的 Xamarin.Forms Page.DisplayAlert 2022-01-01
- 我什么时候应该使用 GC.SuppressFinalize()? 2022-01-01