C# LDAP查询不使用';不能显示某些用户
我无法显示LDAP中的某些用户。我不知道为什么。这是我的密码C# LDAP查询不使用';不能显示某些用户,c#,active-directory,ldap,C#,Active Directory,Ldap,我无法显示LDAP中的某些用户。我不知道为什么。这是我的密码 try { string path = "LDAP://" + Program.domain; DirectoryEntry dEntry = new DirectoryEntry(path); DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
try
{
string path = "LDAP://" + Program.domain;
DirectoryEntry dEntry = new DirectoryEntry(path);
DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
dSearcher.Filter = "(&(objectClass=user)(objectCategory=person))";
//perform search on active directory
sResults = dSearcher.FindAll();
//loop through results of search
foreach (SearchResult searchResult in sResults)
{
//string view = searchResult.Properties["samaccountname"][0].ToString();
// Console.WriteLine(searchResult.Properties["userprincipalname"][0].ToString());
if (searchResult.Properties["samaccountname"][0].ToString() == Program.username)
{
Console.WriteLine("**********UserDetails******************");
foreach (Object propertyName in searchResult.Properties.PropertyNames)
{
ResultPropertyValueCollection valueCollection =
searchResult.Properties[(string)propertyName];
foreach (Object propertyvalue in valueCollection)
{
Console.WriteLine((string)propertyName + " : " + propertyvalue);
result = true;
}
}
Console.WriteLine("************************************");
}
}
这将显示少量用户,但不会显示广告中存在的其他少量用户。
他们也是域管理员和域用户。我还没有看到任何权限问题。。。
我真的需要帮助。有人能帮我吗
谢谢有两种可能的原因: 0)访问控制:您没有适当的访问级别来查看相关对象(或在筛选器中匹配它们所需的属性(无论是
objectClass
还是objectCategory
)
1) 有问题的目标对象实际上与指定的筛选器不匹配。用户可以不是(&(objectClass=user)(objectCategory=person))
我的建议是按以下方式处理这个问题:
0)选取一个您希望匹配的用户样本,仔细检查。检查以确保objectClass实际上包含user,并且objectCategory设置为person。如果没有,请修改查询,使其包含您试图查找的所有用户。(您可以参考广告模式来查看这些内容之间的关系)
1) 确保执行查询的上下文可以访问要查找的所有对象,包括过滤器中使用的属性。如果您无法访问筛选器中的所有属性,AD将不会返回与查询匹配的内容……如果您没有访问权限,这将是一种信息披露形式。这并不是为了回答您的问题,但如果您运行的是.NET 3.5或更高版本,您可能会发现比搜索Active Directory的旧方法更可取。我同意dj的看法。在切换到主要对象之前,我经历了一段痛苦的经历。Program.domain的值是多少?该筛选器将只匹配两个对象类的条目。LDAP客户端使用筛选器
(objectClass=user)
时返回哪些条目?