是否可以从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