[英]ASP.NET - Get the Principal / Relative Identifier (RID) for a DirectoryEntry / SID
我在自定義MembershipProvider類中使用Active Directory來驗證ASP.NET 2.0 Intranet應用程序中的用戶,並將其sid與應用程序的配置文件相關聯。
使用ActiveDirectoryMembershipProvider
, MembershipUser
的ProviderUserKey
對象如下所示
SecurityIdentifier sid = (SecurityIdentifier)Membership.GetUser().ProviderUserKey;
string sidValue = sid.ToString();
/* sidValue = "S-1-5-21-XXXX-XXXX-XXXX-YY" */
據我了解, YY
是命名空間中的主體(也稱為組/域)。
使用自定義MembershipProvider時,我可以使用DirectoryEntry對象的objectSid
屬性獲取sid
DirectoryEntry entry = new DirectoryEntry(path, username, password);
SecurityIdentifier sid = new SecurityIdentifier((byte[])entry.Properties["objectSid"].Value, 0);
string sidValue = sid.ToString();
/* sidValue = "S-1-5-21-XXXX-XXXX-XXXX" */
在這種情況下, sidValue
是相同的,除了它不包含主YY
。
我的問題是雙重的
System.DirectoryServices
可用的任何其他類)獲取主體? 編輯:
做了一些進一步的閱讀( {1} {2} )后,我現在知道如果用戶從一個組/域移動到另一個組/域,sid可能會改變。 鑒於此,使用DirectoryEntry
Properties["objectGUID"]
定義的GUID
是唯一標識用戶的更好選擇嗎?
objectGUID是識別用戶帳戶的最佳選擇。 我強調這一點,因為objectGUID是唯一的,並且對於帳戶實例是固定的。 如果刪除並重新創建具有相同distinguishedName的帳戶,則會獲得不同的objectGUID。 因此,objectGUID不識別用戶,它識別帳戶。
因此,如果要識別帳戶,請使用objectGUID。
有時,管理員可以刪除並重新創建帳戶以解決問題。 如果您需要在發生這種情況后識別用戶,則需要在帳戶對象上選擇其他內容。 這可能需要依賴於您的帳戶定義政策。 也許你有sAMAccountNames不是基於用戶的名字? 也許管理員填充employeeid或employeeNumber? 也許他們強制執行displayNames的唯一性?
這是AD屬性信息的鏈接。 這是DirectoryEntry屬性的鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.