我遇到了以下问题:
我想使用Synologys LDAP服务。工作良好。我的配置是:
- FDQN:";ldap.local">
- 基本DN:";dc=ldap,dc=local">
- 绑定DN:";uid=root,cn=users,dc=ldap,dc=local">
- 允许匿名(仅用于测试!(不要强制SSL
现在我必须从我的c#.net应用程序(.net 6(中检查凭据。我更喜欢使用PrincipalContext而不是ldapconnection。但无论我做什么来创建PrincipalContext,我总是会出错。我的代码是:
string Domain = "192.168.178.79:389";//"192.168.178.79:636";
string dn = "dc=ldap,dc=local";
string User = "uid=admin,cn=users,dc=ldap,dc=local";
string Password = "iWillNotTellYouHere";
ContextOptions options = ContextOptions.SimpleBind;// | ContextOptions.SecureSocketLayer;
PrincipalContext context = new PrincipalContext(ContextType.Domain, Domain, dn, options, User, Password);
构造函数与NullReferenceException
崩溃
我检查了Softerra LDAP浏览器的连接,无论是否使用SSL,它都能正常工作。使用以下参数:
- 主机和基础DN来自上面,默认端口
- URL=";ldaps://192.168.178.79:636/dc=ldap,dc=局部">
- Auth simple
- Principal=";uid=admin,cn=users,dc=ldap,dc=local">
- 全局LDAP密码,我不会在这里告诉它
有什么想法吗???
堆栈跟踪为:
System.NullReferenceException
HResult=0x80004003
Nachricht = Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
Quelle = System.DirectoryServices.AccountManagement
Stapelüberwachung:
at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
at System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, ContextOptions options, String userName, String password)
at DomainTest.Form1.button3_Click(Object sender, EventArgs e) in N:MatthiassourcereposDomainTestDomainTestForm1.cs:line 35
现在我知道问题来源了:
PrincipalContext无法处理OpenLDAP连接
我将不得不使用DirectoryEntry