Click here to Skip to main content
15,908,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have an active directory in my server(Window server 2003) with domain name "mycompany.com". I have another system which is in LAN with the Server, in which I am developing a web application(using C#). I have to fill up a drop-down in my application with the domain list that is present on the server. I am new for working on server OS, and LDAP and Active Directory. Can anyone please help me how I can do this?

Thanks in advance.
Posted

1 solution

Assuming your server is already in the domain, you can use:
C#
List<string> controllers = new List<string>();
Domain domain = Domain.GetCurrentDomain();
foreach (DomainController dc in domain.DomainControllers)
{
  controllers.Add(dc.Name);
}
 
Share this answer
 
Comments
Hiren solanki 17-Nov-10 7:28am    
Good answer, Pete.
bedathur_ganesh 17-Nov-10 7:31am    
Thanks for the help. But, I am not executing the application on server. I am executing it in another system. How can I connect to server from my system to get the domain names?
Pete O'Hanlon 17-Nov-10 7:34am    
Is that other server running in the same domain? If so, the logic still applies.
bedathur_ganesh 17-Nov-10 7:44am    
No, it is not in the same domain. When use your piece of code I am getting an exception saying "Current security context is not associated with an Active Directory domain or forest."
bedathur_ganesh 17-Nov-10 7:46am    
For this, I guess I have to first connect to the server using "LDAP://" kind of a url. But, I am not sure how to connect to the server. Can you please help me?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900