如何从Windows Server 2003获取域名 [英] How to get domain names from Windows Server 2003

查看:152
本文介绍了如何从Windows Server 2003获取域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个装有Windows Server 2003的系统.在这个系统中,我添加了一个DNS域名为"mycompany.com"的Active Directory.现在,我有另一个系统(Win XP),正在其中开发Web应用程序.我的要求是从Web应用程序中获取具有Windows Server 2003的系统中的域名(即"mycompany.com").我正在将C#用于Web应用程序.这两个系统都在LAN中连接.但是,XP系统已登录到域"ABC",而Windows Server系统位于"XYZ"域中.我在下面的代码中使用的IP地址是Windows Server 2003系统的IP,该Windows Server 2003系统位于我的XP系统的局域网中.

我在下面提供了我正在使用的代码:

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);
        }
    }



当我执行此操作时,我在"foreach(adSearcherObject.FindAll()中的SearchResult adObject)"行出现错误未知错误(0x80005000)". (即,在执行"adSearcherObject.FindAll()"时).

请帮助我为什么会出现此错误,以及如何将域名获取到我的应用程序中的下拉列表中.我是LDAP和Active Directory的新手.

在此先感谢您.



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.

推荐答案

您没有正确搜索目录.您可以在此处找到一个示例操作方法 [
You''re not searching the directory properly. Yo ucan find an example of how to do it here[^].


这篇关于如何从Windows Server 2003获取域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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