我需要使用ldap系统将新用户添加到组中。
public bool AddMemberToGroup(string user, string group)
{
user = "cn=" + user + ",ou=People" + uri;
group = "cn=" + group + ",ou=groups";
this.ldapConnection = new DirectoryEntry("LDAP://" + ip +"/" + "cn=testgroup,ou=groups,dc=my,dc=own,dc=path-to-ldap,dc=de", "admin", "adminPW");
this.ldapConnection.AuthenticationType = AuthenticationTypes.Secure;
try
{
this.ldapConnection.Properties["member"].Add(user);
this.ldapConnection.CommitChanges();
this.ldapConnection.Close();
return true;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return false;
}
}
在上面的代码片段中,我得到了错误,表明dn语法无效。当我将AuthenticationTypes
更改为Anonymous
时,出现错误,表明CommitChanges
需要认证。
所以我有两种选择: