我在自定義MembershipProvider類中使用Active Directory來驗證ASP.NET 2.0 Intranet應用程序中的用戶,並將其sid與配置文件相關聯應用程序。ASP.NET - 獲取DirectoryEntry/SID的主體/相對標識符(RID)
當使用ActiveDirectoryMembershipProvider
,所述ProviderUserKey
對象爲MembershipUser
是如下
SecurityIdentifier sid = (SecurityIdentifier)Membership.GetUser().ProviderUserKey;
string sidValue = sid.ToString();
/* sidValue = "S-1-5-21-XXXX-XXXX-XXXX-YY" */
據我所知,YY
是命名空間(也被稱爲一組/域)內的主體。
當使用自定義的MembershipProvider,我可以使用DirectoryEntry對象的屬性objectSid
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
是相同得到的sid,除了它不包含主要YY
。
我的問題是雙重的
- 是爲了唯一識別個人所需的校長?
- 是否可以從DirectoryEntry對象(或通過
System.DirectoryServices
中可用的任何其他類)獲取主體?
編輯:
已經做了一些進一步閱讀({1}{2}),我現在知道,如果用戶從一個組/域移動到另一個SID可以改變。鑑於此,使用DirectoryEntry
Properties["objectGUID"]
中定義的GUID
是唯一識別用戶的更好選擇嗎?
objectGUID是帳戶的GUID還是目錄條目表示的對象類型的GUID?另外,您是否有鏈接指向每個目錄輸入屬性的詳細信息? – 2009-08-13 09:41:53
這是個人帳戶的GUID。如果您使用ADSI Edit MMC管理單元(http://technet.microsoft.com/en-us/library/cc773354(WS.10).aspx),您可以在Active Directory中看到它。 – serialhobbyist 2009-08-14 10:30:56
我已經添加鏈接到主帖子,因爲前一個似乎有點糾結。我不確定是否需要DirectoryEntry對象或AD對象的屬性。在後一種情況下,AD人傾向於將它們作爲屬性來討論。因此,AD類(如用戶)的實例具有諸如displayName之類的屬性。 DirectoryEntry的一個實例具有一個Properties屬性,其中包含一組屬性及其值。它應該被稱爲屬性,IMO。 – serialhobbyist 2009-08-14 10:39:23