2015-04-02 52 views
1

我正试图保存/更新Active Directory中的属性Surname。它与UserPrincipal类很好地工作,但我想使用DirectoryEntry无法保存/更新Active Directory中的属性值

DirectoryEntry保存也行,但不与姓。不知何故,我总是得到例外:

指定目录服务的目录服务属性或值不可用。

代码:

// This part works fine 
var principalUser = UserPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain),IdentityType.SamAccountName, "FirstName.LastName"); 
principalUser.Surname = "LastName"; 
principalUser.Save(); 

// Works not with surname 
DirectoryEntry userEntry = (DirectoryEntry)principalUser.GetUnderlyingObject(); 
userEntry.Properties["surname"].Value = "LastName"; 
userEntry.CommitChanges(); // --> Exception been thrown here 

保存/在UserPrincipal类来更新值时,是什么微软什么不同?

我试图刷新缓存,但它不为我工作:

userEntry.RefreshCache(new string[] { "surname" }); 

编辑:

感谢marc_s我们可以解决这个问题。当你搞乱LDAP中的属性时,务必总是搜索Ldap-Display-Name。 在我的情况https://msdn.microsoft.com/en-us/library/ms679872(v=vs.85).aspx我没有看到attribut姓氏的LDAP的Dipslay-name是“SN”

回答

1

的LDAP属性的名称为 “姓” 是sn - 试试这个:

DirectoryEntry userEntry = (DirectoryEntry)principalUser.GetUnderlyingObject(); 
userEntry.Properties["sn"].Value = "LastName"; 
userEntry.CommitChanges(); 

请参阅Richard Mueller's web site了解非常全面的列表和包含所有相关LDAP属性,其名称和其他属性的Excel工作表

+1

保存我的一天:)。我只是重新检查了msdn文档,我没有看到它的Ldap-Display-Name的姓氏是“sn”https://msdn.microsoft.com/en-us/library/ms679872(v=vs.85).aspx – C0d1ngJammer 2015-04-02 11:05:42

+0

对于*** CN:地址*** Ldap-Display-Name是** streetAddress **。 对于*** CN:街道地址*** Ldap显示名称是**街道**。 – Kiquenet 2016-06-15 11:00:00

相关问题