日期:2014-05-20  浏览次数:20918 次

求助.AD 急.获取组里面的所有的用户.UP也有分!
public   SearchResultCollection   GetuserConunt(DirectoryEntry   de)
        {
                DirectorySearcher   deSearch   =   new   DirectorySearcher();
                deSearch.SearchRoot   =   de;
                deSearch.Filter   =   "(&(objectCategory=person)) ";
                deSearch.SearchScope   =   SearchScope.Subtree;
                return   deSearch.FindAll();

        }

得到的 SearchResultCollection 为空~!很郁闷!!
怎么获取组里面的用户~...求助~!

------解决方案--------------------
断点跟踪调试一下。
------解决方案--------------------
断点跟踪调试一下。
------解决方案--------------------
up
------解决方案--------------------
继续关注
------解决方案--------------------
听说UP也有分
------解决方案--------------------
up
------解决方案--------------------
听说UP有分
------解决方案--------------------
up
------解决方案--------------------
up
------解决方案--------------------
/// <summary>
/// 读取AD用户信息
/// </summary>
/// <param name= "ADUsername "> 用户 </param>
/// <param name= "ADPassword "> 密码 </param>
/// <param name= "domain "> 域名 </param>
/// <returns> </returns>
public static SortedList AdUserInfo(string ADUsername, string ADPassword, string domain ,Label lb)
{
DirectorySearcher src;
string ADPath = "LDAP:// " + domain;// "ou=总公司,DC=abc,DC=com,DC=cn "; + ",ou=总公司 "
SortedList sl = new SortedList();
string GroupName = string.Empty;
GroupName = "总公司 ";
DirectoryEntry de = new DirectoryEntry(ADPath, ADUsername, ADPassword);
string domainFilter=ConfigurationManager.AppSettings[ "DomainFilter "].ToString();
if (domainFilter != string.Empty || domainFilter != " ")
{
domainFilter = domainFilter.Replace( "_ ", "& "); //( "(&(objectCategory=person)(objectClass=user)) ");
src = new DirectorySearcher(domainFilter);
}
else
{
src = new DirectorySearcher();
}
src.SearchRoot = de;
src.PageSize = 10000;// 此参数可以任意设置,但不能不设置,如不设置读取AD数据为0~999条数据,设置后可以读取大于1000条数据。
// src.SizeLimit = 2000;
src.SearchScope = SearchScope.Subtree;
try
{
foreach (SearchResult res in src.FindAll()) // foreach (SearchResult res in src.FindAll()) foreach (DirectoryEntry res in de.Children)
{
//if (res.GetDirectoryEntry().Properties[ "EmailAddress "].Value != " ")
//{
sl.Add(res.GetDirectoryEntry().Properties[ "Name "].Value, res.GetDirectoryEntry().InvokeGet( "Description "));