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

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

附言我的计算机已加入 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/

相关文章:

c# - 使用游标从使用 C# 的 SQL Server 读取时间序列数据?

java - OpenLDAP LDAPConnection.bind() dn 字符串中可以使用通配符吗?

java - OpenLDAP 仅返回密码过期的警告

c# - 获取本地组的成员

c# - 为应用程序选择众多 Internet 连接之一

c# - HP-UFT WPF TextBlock 对象捕获

c# - 什么样的 RSASignaturePadding 与 PKCS#8 key 一起使用?

java - 如何在 JSP 中找到 LDAP 用户的 DN?

c# - UserPrincipal.FindByIdentity() 总是返回 null