Bea*_*692 4 c# openldap principalcontext
我已经安装了openldap for windows服务器,并使用LDAPAdmin其默认值连接至该服务器:
Server=ldap://localhost:389
Base:dc=maxcrc,dc=com
UserName:cn=Manager,dc=maxcrc,dc=com
Password:secret
Run Code Online (Sandbox Code Playgroud)
现在,我想用来PrincipalContext向用户添加用户ou=People
。问题是,我什至无法使用PrincipalContext连接到服务器。我已经在网上搜索了很多关于如何连接到ldap服务器的答案,但是没有一个对我有用。我一直在为PrincipalContext构造函数提供一个NullReferenceException或多个ServerNotFoundException不同的组合参数。我以为可以使用PrincipalContext作为以下之一:
new PirncipalContext(ContextType.Domain,"maxcrc.com","dc=maxcrc,dc=com")
Run Code Online (Sandbox Code Playgroud)
要么
new PrincipalContext(ContextType.ApplicationDirectory,"localhost:389","dc=maxcrc,dc=com")
Run Code Online (Sandbox Code Playgroud)
但是它们都没有起作用。有人说我应该提供用户名和密码,所以我做到了,但我不断出现异常。
因此,请告诉我如何使用PrincipalContext连接到openldap?
PS我的计算机已加入Active Directory域控制器。
System.DirectoryServices.AccountManagement命名空间可跨多个主体存储(Active Directory域服务(AD DS),Active Directory轻型目录服务(AD LDS)和计算机SAM( MSAM)。System.DirectoryServices.AccountManagement管理与System.DirectoryServices命名空间无关的目录对象。
这些类仅对Active Directory有用- 无法移植到其他“通用” LDAP存储中。
如果您需要支持OpenLDAP,请使用DirectoryEntry和这些功能,或者使用较低级别的System.DirectoryServices.Protocol(裸LDAP)层。