PrincipalContext - 我无法连接到本地 openldap 服务器

PrincipalContext - I Can't connect to a local openldap server

我已经安装了一个 openldap for windows 服务器,我使用 LDAPAdmin 以默认值连接到它:

Server=ldap://localhost:389
Base:dc=maxcrc,dc=com
UserName:cn=Manager,dc=maxcrc,dc=com
Password:secret

现在我想使用 PrincipalContext 将用户添加到我的 ou=People 问题是我什至无法使用 PrincipalContext 连接到服务器。我在网上搜索了很多关于如何连接到 ldap 服务器的答案,但是 none 正在为 me.I 继续获得 NullReferenceExceptionServerNotFoundException为 PrincipalContext 构造函数提供的参数的不同组合。 我想我可以使用 PrincipalContext 作为以下之一:

new PirncipalContext(ContextType.Domain,"maxcrc.com","dc=maxcrc,dc=com")

new PrincipalContext(ContextType.ApplicationDirectory,"localhost:389","dc=maxcrc,dc=com")

但是 none 其中 working.Some 说我应该提供用户名和密码,所以我这样做了,但我总是收到异常。

所以请告诉我如何使用 PrincipalContext 连接到 openldap?

P.S。我的计算机已加入 Active Directory 域控制器。

official documentation on MSDN 所述:

The System.DirectoryServices.AccountManagement namespace provides uniform access and manipulation of user, computer, and group security principals across the multiple principal stores: Active Directory Domain Services (AD DS), Active Directory Lightweight Directory Services (AD LDS), and Machine SAM (MSAM). System.DirectoryServices.AccountManagement manages directory objects independent of the System.DirectoryServices namespace.

那些 类 仅对 Active Directory 有用 - 它们 不能 可移植到其他 "generic" LDAP 存储。

如果您需要支持 OpenLDAP,请使用 DirectoryEntry 和那些函数,或者使用较低级别的 System.DirectoryServices.Protocol(基本 LDAP)层。