我已经安装了一个 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 服务器的答案,但没有一个对我有用。我一直收到 NullReferenceException
或 ServerNotFoundException
为 PrincipalContext 构造函数提供的参数的不同组合。
我想我可以使用 PrincipalContext 作为以下之一:
new PirncipalContext(ContextType.Domain,"maxcrc.com","dc=maxcrc,dc=com")
或
new PrincipalContext(ContextType.ApplicationDirectory,"localhost:389","dc=maxcrc,dc=com")
但它们都不起作用。有人说我应该提供用户名和密码,所以我这样做了,但我一直收到异常。
所以请告诉我如何使用 PrincipalContext 连接到 openldap?
附言我的计算机已加入 Active Directory 域 Controller 。
最佳答案
作为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 有用 - 它们不能移植到其他“通用”LDAP 存储。
如果您需要支持 OpenLDAP,请使用 DirectoryEntry
和那些函数,或者使用较低级别的 System.DirectoryServices.Protocol
(基本 LDAP)层。
关于c# - PrincipalContext - 我无法连接到本地 openldap 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28988638/