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

时间:2015-03-11 14:01:04

标签: 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

现在我想使用PrincipalContext将用户添加到我的ou=People 问题是我甚至无法使用PrincipalContext连接到服务器。我搜索了网络并找到了很多关于如何连接到ldap服务器的答案,但没有一个能为我工作。我不断获得NullReferenceExceptionServerNotFoundException的不同组合提供的参数PrincipalContext构造函数。 我以为我可以使用PrincipalContext作为以下之一:

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

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

但他们都没有工作。有人说我应该提供用户名和密码,所以我这样做了,但我一直有例外。

那么请告诉我如何使用PrincipalContext连接到openldap?

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

1 个答案:

答案 0 :(得分:4)

正如official documentation on MSDN所述:

  

System.DirectoryServices.AccountManagement命名空间提供对多个主要存储中的用户,计算机和组安全主体的统一访问和操作: Active Directory 域服务(AD DS),< strong> Active Directory 轻量级目录服务(AD LDS)和机器SAM(MSAM)。 System.DirectoryServices.AccountManagement管理独立于System.DirectoryServices名称空间的目录对象。

这些类仅对 Active Directory 有用 - 它们可移植到其他“通用”LDAP商店。

如果您需要支持OpenLDAP,请使用DirectoryEntry和这些功能,或使用较低级别System.DirectoryServices.Protocol(简单LDAP)图层。

相关问题