问题描述
我如何限制在通过的System.DirectoryServices LDAP查询返回的属性?
How do I limit the attributes that are returned in an LDAP query through System.DirectoryServices?
我一直在使用一个DirectorySearcher从和补充,我想DirectorySearcher.PropertiesToLoad的属性。的问题是,这只是可以确保所添加的属性被包括在DirectoryEntry.Properties以及一些默认列表。有没有什么办法来指定要返回的唯一属性?
I have been using a DirectorySearcher and adding the properties that I want to DirectorySearcher.PropertiesToLoad. The problem is that this just makes sure that the added properties are included in the DirectoryEntry.Properties as well as some default list. Is there any way to specify the only properties that you want returned?
DirectoryEntry base = new DiectoryEntry(rootPath, null, null, AuthenticationTypes.FastBind);
DirectorySearcher groupSearcher = new DirectorySearcher(base);
groupSearcher.Filter = "(objectClass=group)";
groupSearcher.PropertiesToLoad.Add("distinguishedName");
groupSearcher.PropertiesToLoad.Add("description");
foreach (SearchResult groupSr in groupDs.FindAll())
...
里面的foreach循环,当我拿到小组第一的DirectoryEntry有,我可以访问不只是我指定的两个大约16个不同的属性(distinguishedName来,说明)
Inside the foreach loop when I get the group DirectoryEntry there are about 16 different properties that I can access not just the two that I specified (distinguishedName, description)
推荐答案
你限制的东西有,将可在性能/填充你的信息搜索结果
对象 - 你可以直接访问你的的foreach
循环:
The thing you're limiting there are the properties that will be available / filled in your SearchResult
objects - which you can access directly in your foreach
loop:
DirectoryEntry baseEntry = new DirectoryEntry(rootPath, null, null, AuthenticationTypes.FastBind);
DirectorySearcher groupSearcher = new DirectorySearcher(baseEntry);
groupSearcher.Filter = "(objectClass=group)";
groupSearcher.PropertiesToLoad.Add("distinguishedName");
groupSearcher.PropertiesToLoad.Add("description");
foreach (SearchResult groupSr in groupSearcher.FindAll())
{
if(groupSr.Properties["description"] != null && groupSr.Properties["description"].Count > 0)
{
string description = groupSr.Properties["description"][0].ToString();
}
.....
}
您不能实际限制的属性的DirectoryEntry
- 所以,如果你去抓住每一个目录条目信息搜索结果
- 你可以完全访问一切。但整个的一点是,你可以定义你需要什么样的属性,以及访问这些直接在信息搜索结果
,没有不必返回到底层的DirectoryEntry
You cannot limit the properties on the actual DirectoryEntry
- so if you go grab the directory entry for each SearchResult
- you have full access to everything. But the whole point is that you can define what properties you need, and access those directly on the SearchResult
, without having to go back to the underlying DirectoryEntry
这篇关于限制LDAP查询返回的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!