一、首先创建一个LDAP连接
二、创建一个LdapEntry,首先要创建LdapAttributeSet(一个包括用户所有信息的属性集)
三、将这个LdapAttributeSet添加到LdapEntry中,再执行新增操作
LdapConnection ldapConn=new LdapConnection();
ldapConn.Connect(ldapHost,ldapPort);//这里需要传入LDAP服务器的IP地址和端口号
ldapConn.Bind(userDn,userPwd);//这里需要的是登陆LDAP服务器的用户名和密码
LdapAttributeSet attribute=new LdapAttributeSet();
attributeSet.Add(new LdapAttribute("objectclass","inetOrgPerson"));//这里先添加了一个objectclass属性
attributeSet.Add(new LdapAttribute("cn","dean"));
//当我们准备好一系列的属性后
string dn="cn=dean";
LdapEntry new Entry =new LdapEntry(dn,attributeSet);//将整个属性集添加到LdapEntry中
LdapConn.Add(newEntry);//将LdapEntry添加到LDAP中