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

冷暖自知 提交于 2019-12-22 08:27:06

问题


I have installed an openldap for windows server and I use LDAPAdmin to connect to it by its default values :

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

Now I want to use PrincipalContext to add users to my ou=People The problem is I can't even connect to the server using PrincipalContext. I have searched the Net and found a lot of answers on how to connect to a ldap server but none of them are working for me.I keep getting a NullReferenceException or ServerNotFoundException for different combination of provided parameters for PrincipalContext constructor. I thought I could use PrincipalContext as one of the follows :

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

or

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

but none of them are working.Some say that I should provide username and password so I did that but I keep getting exception.

So please tell me how can I use PrincipalContext to connect to openldap ?

P.S. My computer is already joined to an Active Directory domain controller.


回答1:


As the official documentation on MSDN states:

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.

Those classes are useful for Active Directory only - they are not portable to other, "generic" LDAP stores.

If you need to support OpenLDAP, either use DirectoryEntry and those functions, or use the lower level System.DirectoryServices.Protocol (bare-bones LDAP) layer.



来源:https://stackoverflow.com/questions/28988638/principalcontext-i-cant-connect-to-a-local-openldap-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!