【发布时间】:2014-09-03 00:56:58
【问题描述】:
我无法从 PasswordNeverExpires 等用户对象中获取某些字段。现在我正在循环浏览超过 2000 个用户返回的每个属性,并且我的条件断点从未中断过一次,所以我知道它不会返回。如果我无条件中断,则此代码返回的属性数始终为 1。 我们的服务器是 Windows 2003 Server。我可以从 NetEnum 命令中获得我想要的所有信息。 我看到其他人声称他们可以做到这一点,但我看不出我的代码有什么不同。当我不提供任何要加载的属性时,它会抓取大约 30-37 个属性。我需要和使用其中的几个属性。
public void FetchUsers(string domainId, Sql sql)
{
var entry = new DirectoryEntry("LDAP://" + DomainControllerAddress, DomainPrefixedUsername, Password,
AuthenticationType);
var dSearch = new DirectorySearcher(entry)
{
Filter = "(&(objectClass=user)(!(objectclass=computer)))",
SearchScope = SearchScope.Subtree,
PageSize = 1000,
};
dSearch.PropertiesToLoad.Add("passwordneverexpires");
var users = dSearch.FindAll();
foreach (SearchResult ldapUser in users)
{
SaveUser(ldapUser, sql, domainId);
}
}
private void SaveUser(SearchResult ldapUser, Sql sql, string domainId)
{
if (ldapUser.Properties.PropertyNames == null) return;
foreach (string propertyName in ldapUser.Properties.PropertyNames)
{
//I'm breaking here on the condition that propertyName != 'adspath' and it never breaks
var v = ldapUser.Properties[propertyName];
}
return;
}
【问题讨论】:
标签: c# active-directory ldap directorysearcher