2015-04-02 53 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

相關問題