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

I have an ASP.NET Website project, and I need to list all users and their groups on my Windows system. I set the identity impersonation to true and provided the administrator username and password in the web.config file. Where to begin?

Thanks in advance.

Update:

I have the following code at the moment -

var machine = new DirectoryEntry("WinNT://<IP ADDRESS>"); foreach (DirectoryEntry child in machine.Children) { // get the child group(s). } 

When I debug, I see a list of users in machine.Children. How to find the group (s) to which this user belongs?

+4
source share
2 answers

This article talks about how to talk to Active Directory and you have to find where you want to go: http://www.codeproject.com/KB/system/everythingInAD.aspx

To get users, you would do something like this:

 public List<string> GetUserList() { string DomainName=""; string ADUsername=""; string ADPassword=""; List<string> list=new List<string>(); 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; } 
+2
source

You probably want to start by supporting DirectoryEntry and Active Directory in .net.

Here's a good resource: http://www.codeproject.com/KB/system/everythingInAD.aspx

Local access is the same even if you are not in a domain:

 DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName); DirectoryEntry admGroup = localMachine.Children.Find("administrators", "group"); object members = admGroup.Invoke("members", null); foreach (object groupMember in (IEnumerable)members) { DirectoryEntry member = new DirectoryEntry(groupMember); //... } 
+2
source

All Articles