我试图制作一个Visual Studio程序,让您可以将用户添加到Active Directory中。无论何时添加用户,我都会收到错误“指定了无效的DN语法”。我不知道这个错误究竟意味着什么,并且谷歌学会了我,它可能是一些事情。下面是相关代码:指定了无效的DN语法 - Visual Studio错误
string UserName = txt_UserName.Text;
string Department = ddl_Department.SelectedItem.ToString(); //The chosen OU
string LDAPstring = "LDAP://OU=" + Department + ",DC=group0, DC=han";
DirectoryEntry dirEntry = new DirectoryEntry(LDAPstring);
//Make a USER Object
DirectoryEntry newUser = dirEntry.Children.Add(UserName, "user");
newUser.CommitChanges(); //User is made
newUser.Properties["userprincipalname"].Add(txt_UserName.Text + "@group0.han");
newUser.Properties["samaccountname"].Value = txt_UserName.Text;
newUser.CommitChanges(); //User is given properties
这是否有帮助:http://stackoverflow.com/questions/16168267/directoryentries-find-an-invalid-dn-syntax-has-been-specified? –
不,看起来像我有另一个问题 – Edeholland
'部门'的价值是什么?更好的是,LDAPstring的全部价值是什么? –