简体   繁体   中英

Update user with new custom attribute C# LDAP

I need update a specific user ldap with new custom attributes. When run throw Exception "Unhandled Exception: System.DirectoryServices.DirectoryServicesCOMException: The specified directory service attribute or value does not exist". My code is:

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();
}

运行我的代码并获得成功的结果后,在“ Active Directory架构”中添加海关属性,并分配给用户类作为可选属性

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM