【发布时间】:2013-01-24 00:08:08
【问题描述】:
我无法显示来自 LDAP 的一些用户。我不知道为什么。这是我的代码
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("************************************");
}
}
这会显示少数用户,但不会显示 AD 中存在的其他少数用户。 他们也是域管理员和域用户。我还没有看到任何权限问题... 我真的需要一些帮助。有人可以帮帮我吗?
谢谢
【问题讨论】:
-
这不是为了回答您的问题,但如果您运行的是 .NET 3.5 或更高版本,您可能会发现 System.DirectoryServices.AccountManagement API 比搜索 Active Directory 的旧方法更可取。
-
我同意 dj 的观点。在切换到 Principal 对象之前,我的经历很悲惨。
-
Program.domain 的值是多少?
-
该过滤器将仅匹配具有两个 objectClasses 的条目。 LDAP 客户端使用过滤器
(objectClass=user)时返回哪些条目?
标签: c# active-directory ldap