How to list Windows users and groups in ASP.NET?

后端 未结 2 567
我在风中等你
我在风中等你 2020-12-11 08:32

I have a ASP.NET Website project and I need to list all the users and their groups on my Windows system. I have set the identity impersonation to true and provided the usern

2条回答
  •  暖寄归人
    2020-12-11 08:59

    This article covers how to talk to Active Directory and should get you where you want to go: http://www.codeproject.com/KB/system/everythingInAD.aspx

    To get users, you would do something like this:

    public List GetUserList()
    {
            string DomainName="";
            string ADUsername="";
            string ADPassword="";
    
            List list=new List();
            DirectoryEntry entry=new DirectoryEntry(LDAPConnectionString, ADUsername, ADPassword);
            DirectorySearcher dSearch=new DirectorySearcher(entry);
            dSearch.Filter="(&(objectClass=user))";
    
            foreach(SearchResult sResultSet in dSearch.FindAll())
            {
                string str=GetProperty(sResultSet, "userPrincipalName");
                if(str!="")
                    list.Add(str);
            }
            return list;
    }
    

提交回复
热议问题