我試圖製作一個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的全部價值是什麼? –