使用新的自定义属性C#LDAP更新用户

时间:2018-06-12 18:39:19

标签: c# active-directory ldap

我需要使用新的自定义属性更新特定用户ldap。当run throw Exception" Unhandled Exception:System.DirectoryServices.DirectoryServicesCOMException:指定的目录服务属性或值不存在"。我的代码是:

using (var entryRoot = new DirectoryEntry("LDAP://ldap.com:389/OU=CATALOG,DC=ldap,DC=com", "juan", "juan2016", AuthenticationTypes.Secure)){
    DirectorySearcher user_searcher = new DirectorySearcher(entryRoot);

    user_searcher.Filter = $"(&(objectCategory=person)(objectClass=user)(samAccountName={cn1}))"

    user_searcher.PropertiesToLoad.Add("identification");

    SearchResultCollection result = user_searcher.FindAll();

    DirectoryEntry user_ldap = result[0].GetDirectoryEntry();

    user_ldap.Properties["identification"].Value = identification;

    user_ldap.CommitChanges();
}

1 个答案:

答案 0 :(得分:0)

在" Active Directory架构中添加海关属性"在破坏了我的代码和成功的结果后,将用户类分配为可选属性