活动目录用户 [英] Active directory users

查看:60
本文介绍了活动目录用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在网络应用程序中我需要从活动目录中取出所有用户,有人可以帮我解决这个问题,我用Google搜索并得到了许多代码,没有一个工作正常,有人可以为此提供工作代码吗?早期的反应将不胜感激。

解决方案

参考此链接:



http://forums.asp.net/t/1333847.aspx/1 [ ^ ]


试试这个:

Active Directory登录 [ ^ ]



在此链接中我解释了一切。这对工作目录很有帮助。







--Amit

 使用(DirectoryEntry domain =  new  DirectoryEntry(  LDAP:// + domainToBeSearched))
{
< span class =code-keyword> using (DirectorySearcher searcher = new DirectorySearcher())
{
// 设置搜索的根
searcher.SearchRoot = domain;
// 设置搜索用户的过滤器
searcher.Filter = FormFilter(< span class =code-string> user,userName + *);
searcher.SearchScope = SearchScope.Subtree;
searcher.PageSize = 10 ;
// 根据传递的过滤器获取所有注册用户
使用(SearchResultCollection adResult = searcher.FindAll())
{
DataRow dtrUsers = null ;
foreach (SearchResult结果 in adResult)
{
if (dtUsers.Select( key =' + result.Properties [ samaccountname] [ 0 ]。ToString()+ ')。长度< = 0
{
// 将用户添加到datatable
dtrUsers = dtUsers.NewRow();
dtrUsers [ 0 ] = result.Properties [ samaccountname] [ 0 ]。ToString();
dtrUsers [ 1 ] = result.Properties [ DisplayName] [ 0 ];
dtUsers.Rows.Add(dtrUsers);
}

}
}
}
}







希望这应该有效,如果有任何问题请纠正我!


Hi,

in web application i need to pull out all the users from active directory, can some one help me out on this, i googled and got so many code, none is working fine, can some one provide the working code for this? early response would be appreciated.

解决方案

Refer this link:

http://forums.asp.net/t/1333847.aspx/1[^]


Try this:
Active Directory login[^]

Here in this link I explained everything. This will help you a lot in case of working directory.



--Amit


using (DirectoryEntry domain = new DirectoryEntry("LDAP://" + domainToBeSearched))
{
    using (DirectorySearcher searcher = new DirectorySearcher())
    {
        //Set root for searching
        searcher.SearchRoot = domain;
        //Set filters for searching user
        searcher.Filter = FormFilter("user", userName + "*");
        searcher.SearchScope = SearchScope.Subtree;
        searcher.PageSize = 10;
        //Get all registered user on basis of passed filter
        using (SearchResultCollection adResult = searcher.FindAll())
        {
            DataRow dtrUsers = null;
            foreach (SearchResult result in adResult)
            {
                if (dtUsers.Select("key='" + result.Properties["samaccountname"][0].ToString() + "'").Length <= 0)
                {
                    //Add user to datatable
                    dtrUsers = dtUsers.NewRow();
                    dtrUsers[0] = result.Properties["samaccountname"][0].ToString();
                    dtrUsers[1] = result.Properties["DisplayName"][0];
                    dtUsers.Rows.Add(dtrUsers);
                }

            }
        }
    }
}




hope this should work, correct me if any issues!


这篇关于活动目录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆