是否可以從LDAP中檢索所有屬性/值的列表,而無需指定,如果是這樣怎麼可能?LDAP - 檢索所有屬性/值的列表?
回答
指定「*」作爲要返回的屬性列表中的唯一值。
如果您還想要操作屬性,請將「+」添加到列表中。
非常感謝你。 search.PropertiesToLoad.Add(「*」); search.PropertiesToLoad.Add(「+」); – DFTR
你可以使用一個DirectoryEntry來生成一個屬性列表,你當然必須使用每個屬性列表來查看。
DirectoryEntry objADAM = default(DirectoryEntry);
string properties = string.Empty;
foreach (string property in objADAM.Properties.PropertyNames)
{
properties += property + ", ";
}
你總是可以但是參考
http://www.codeproject.com/KB/system/everythingInAD.aspx
當它涉及到C#和Active Directory。
UPDATE:http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C
是的 - 但是隻有**纔會獲得那些賦予它們值的屬性,對於那個特定的'DirectoryEntry'。這沒有**枚舉整個可能的屬性列表..... –
'http:// www.codeproject.com/KB/system/everythingInAD.aspx'找不到 – Kiquenet
井「retreiving所有屬性」獨自一人,只要目錄擔心是沒有意義的。 你的意思是:
- 所有的用戶可能的屬性,因爲他們在模式discribed
- 重視所有的用戶屬性
- 所有的用戶和業務屬性
而且我不照顧某些用戶屬性可以是隻讀的,而其他的只能用特定的值寫入。我添加了獲取內容的方式。
@Ghostfire爲解決所有用戶屬性的價值和操作屬性提供瞭解決方案。
DirectoryEntry deUser = new DirectoryEntry("LDAP://WM2008R2ENT:389/CN=AUser,OU=MonOu,DC=dom,DC=fr");
foreach (string property in deUser.Properties.PropertyNames)
{
Console.WriteLine("\t{0} : {1} ", property, deUser.Properties[property][0]);
}
但請記住,在LDAP搜索時,最好的辦法是給你想中檢索的attributs:
/* Connection to Active Directory
*/
DirectoryEntry deBase = new DirectoryEntry("LDAP://WM2008R2ENT:389/dc=dom,dc=fr");
/* Directory Search
*/
DirectorySearcher dsLookFor = new DirectorySearcher(deBase);
dsLookFor.Filter = "(sn=users)";
dsLookFor.SearchScope = SearchScope.Subtree;
dsLookFor.PropertiesToLoad.Add("cn");
dsLookFor.PropertiesToLoad.Add("givenName");
dsLookFor.PropertiesToLoad.Add("telephoneNumber");
dsLookFor.Sort = new SortOption("givenName", SortDirection.Descending);
dsLookFor.VirtualListView = new DirectoryVirtualListView(1, 0, 2);
SearchResultCollection srcUsers = dsLookFor.FindAll();
我抓住所有參數的清單我的DirectoryEntry類對象。我希望這將有助於:
objectClass = System.Object[]
cn = Administrator
sn = Kwiatek (Last name)
c = PL (Country Code)
l = Warszawa (City)
st = Mazowieckie (Voivodeship)
title = .NET Developer
description = Built-in account for administering the computer/domain
postalCode = 00-000
postOfficeBox = Warszawa Ursynów
physicalDeliveryOfficeName = Wojskowa Akademia Techniczna
givenName = Piotr (First name)
distinguishedName = CN=Administrator,CN=Users,DC=helpdesk,DC=wat,DC=edu
instanceType = 4
whenCreated = 2012-11-23 06:09:28
whenChanged = 2013-02-23 13:24:41
displayName = Piotr Kwiatek (Konto administratora)
uSNCreated = System.__ComObject
memberOf = System.Object[]
uSNChanged = System.__ComObject
co = Poland
company = HELPDESK
streetAddress = Kaliskiego 2
wWWHomePage = http://www.piotr.kwiatek.org
name = Administrator
objectGUID = System.Byte[]
userAccountControl = 512
badPwdCount = 0
codePage = 0
countryCode = 616
badPasswordTime = System.__ComObject
lastLogoff = System.__ComObject
lastLogon = System.__ComObject
logonHours = System.Byte[]
pwdLastSet = System.__ComObject
primaryGroupID = 513
objectSid = System.Byte[]
adminCount = 1
accountExpires = System.__ComObject
logonCount = 178
sAMAccountName = Administrator
sAMAccountType = 805306368
objectCategory = CN=Person,CN=Schema,CN=Configuration,DC=helpdesk,DC=wat,DC=edu
isCriticalSystemObject = True
dSCorePropagationData = System.Object[]
lastLogonTimestamp = System.__ComObject
mail = [email protected]
nTSecurityDescriptor = System.__ComObject
,在這裏你有代碼:
string currentUserSid = WindowsIdentity.GetCurrent().User.Value;
PrincipalContext ctx = new PrincipalContext(
ContextType.Domain,
"helpdesk.wat.edu");
UserPrincipal up = UserPrincipal.FindByIdentity(
ctx, IdentityType.Sid,
currentUserSid);
/*
*
*/
DirectoryEntry entry = up.GetUnderlyingObject() as DirectoryEntry;
PropertyCollection props = entry.Properties;
/*
*
*/
foreach (string propName in props.PropertyNames)
{
if (entry.Properties[propName].Value != null)
{
Console.WriteLine(propName + " = " + entry.Properties[propName].Value.ToString());
}
else
{
Console.WriteLine(propName + " = NULL");
}
}
Console.ReadKey();
如何獲取'系統的值。對象[]','System .__ ComObject','System.Byte []'等等***屬性***? – Kiquenet
// This will list ALL the properties from AD (between 200 and 800..or more)
// If someone has a solution for non AD servers please post it!
List<String> properties = new List<String>();
IPAddress[] ips = Dns.GetHostAddresses(Server).Where(w => w.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToArray();
if (ips.Length > 0)
{
DirectoryContext directoryContext = new DirectoryContext(DirectoryContextType.DirectoryServer, ips[0].ToString() + ":389", Username, Password);
ActiveDirectorySchema adschema = ActiveDirectorySchema.GetSchema(directoryContext);
ActiveDirectorySchemaClass adschemaclass = adschema.FindClass("User");
// Read the OptionalProperties & MandatoryProperties
ReadOnlyActiveDirectorySchemaPropertyCollection propcol = adschemaclass.GetAllProperties();
foreach (ActiveDirectorySchemaProperty schemaProperty in propcol)
properties.Add(schemaProperty.Name.ToLower());
}
哪個***命名空間用於'DirectoryContext'? – Kiquenet
using System.DirectoryServices.ActiveDirectory; –
對於你應該看看查詢特定對象類的架構的所有可能的屬性的列表。
- 1. 檢索ldap3中所有屬性的列表(python3-ldap)
- 2. 如何檢索LDAP數據庫上的所有LDAP屬性定義?
- 3. HTML rel屬性的所有值列表
- 4. XPATH檢索屬性列表
- 5. Lambda檢查列表是否包含所有屬性的某些屬性值
- 6. 檢索屬性值
- 7. 用於檢索sAMAccountName屬性值的Jython LDAP腳本
- 8. 如何從常用對象列表中檢索所有屬性值?
- 9. 命令行搜索所有html文件,檢索屬性值
- 10. 檢索的getJSON屬性值
- 11. LDAP模板搜索屬性
- 12. 檢索列中的所有值
- 13. 檢索Azure表的屬性
- 14. 檢索到的JSON列表/數組,無法訪問AngularJS上的所有屬性
- 15. 使用XSLT從XML檢索所有屬性值
- 16. 檢索模型屬性值
- 17. DelegatingFilterProxy檢索屬性值
- 18. 從XML屬性檢索值
- 19. 根據屬性值檢索列表中的不同對象
- 20. 檢索多值屬性DN使用ActiveLdap
- 21. LDAP替換一個屬性的列表值
- 22. 無法列出所有LDAP屬性使用C#
- 23. 獲取所有XML屬性的列表
- 24. 迭代列表中的所有屬性
- 25. 檢索列表中的所有對象是否具有相同的python屬性值
- 26. VBScript:從對象屬性中檢索值
- 27. LDAP中多值屬性中的單值
- 28. HtmlAgilityPack節點和屬性的所有值的列表
- 29. Mysql - 如何檢索沒有特定屬性的所有項目?
- 30. 如何從Redis的列表中檢索所有哈希值?
您是否使用'PrincipalContext'獲得最終解決方案?您使用哪種.NET Framework版本? – Kiquenet