【发布时间】:2019-01-18 18:59:57
【问题描述】:
我正在尝试更新用户属性,但出现错误:
为目录服务指定的属性语法无效
当我执行CommitChanges() 时会发生这种情况,此代码之前对我有用,所以我不知道出了什么问题。
这是代码:
DirectoryEntry de = new DirectoryEntry(_ldap);
DirectorySearcher ds = new DirectorySearcher(de) { Filter = "(&(objectClass=user)(SamAccountName=" + logon_tb.Text + "))" };
SearchResult sr = ds.FindOne();
DirectoryEntry userEntry = sr.GetDirectoryEntry();
try { userEntry.Properties["givenName"].Value = fn_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["sn"].Value = ln_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["displayName"].Value = dispName_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["description"].Value = description_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["physicalDeliveryOfficeName"].Value = office_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["telephoneNumber"].Value = telephone_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["mobile"].Value = mobile_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["title"].Value = jobTitle_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["department"].Value = department_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["postOfficeBox"].Value = poBox_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["homeDirectory"].Value = homeFolder_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["extensionAttribute10"].Value = extAtt10_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["extensionAttribute11"].Value = extAtt11_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["extensionAttribute12"].Value = extAtt12_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["extensionAttribute13"].Value = extAtt13_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["extensionAttribute14"].Value = extAtt14_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["extensionAttribute15"].Value = extAtt15_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["SamAccountName"].Value = logon_tb.Text; }
catch (Exception) { }
try { userEntry.Properties["userPrincipalName"].Value = logonPrincipal_tb.Text; }
catch (Exception) { }
if (pwNeverExpire_cb.Checked)
userEntry.Properties["userAccountControl"].Value = 66048;
userEntry.CommitChanges();
userEntry.Close();
【问题讨论】:
-
我发现,当一个文本框为空时,我收到了错误,所以如果文本框有一个值,它将被更新,否则该属性将为空。无论如何谢谢:)
-
您可能想留下解决您问题的答案!这肯定会帮助未来的访客。另外,请将该答案标记为已接受。干杯...
标签: c# active-directory syntax-error