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

I have a system with Windows Server 2003. In this system, I have added an Active Directory with DNS Domain name as "mycompany.com". Now, I have another system(Win XP), in which I am developing a web application. My requirement is to get the domain name in the system with Windows Server 2003,(i.e., "mycompany.com") from the webapplication. I am using C# for web application. Both these systems are connected in LAN. But, XP system is logged in to a domain "ABC", where as Windows Server system is in "XYZ" domain. The IP address that I have used in the code below, is the IP of the Windows Server 2003 system which is in LAN with my XP system.

I am giving the code that I am using below:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddDomains.Items.Clear();
            ddDomains.Items.Add(new ListItem("Select a Domain", "0"));
        }
    }
    private StringCollection GetDomainList()
    {
        StringCollection domainList = new StringCollection();
        try
        {
            DirectoryEntry adFolderObject = new DirectoryEntry("LDAP://192.168.10.100/");
            DirectorySearcher adSearcherObject = new DirectorySearcher(adFolderObject);
            adSearcherObject.SearchScope = SearchScope.Subtree;
            adSearcherObject.Filter = "objectCategory=Domain";
            foreach (SearchResult adObject in adSearcherObject.FindAll())
            {
                domainList.Add(adObject.ToString());
            }
        }
        catch (Exception ex)
        {
            Trace.Write(ex.Message);
        }
        return domainList;
    }
    protected void btnGetDomains_Click(object sender, EventArgs e)
    {
        StringCollection adDomains = this.GetDomainList();
        foreach (string strDomain in adDomains)
        {
            ddDomains.Items.Add(strDomain);
        }
    }


when I execute this, I ma getting an error "Unknown error (0x80005000)" at the line "foreach (SearchResult adObject in adSearcherObject.FindAll())". ( i.e., while executing "adSearcherObject.FindAll()").

Please help me why I am getting this error, and how to get the domain name to the dropdown list in my application. I am new to the LDAP and Active Directory stuff.

Thanks in advance.
Posted

1 solution

You're not searching the directory properly. Yo ucan find an example of how to do it here[^].
 
Share this answer
 

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