We need more information to give you a good answer. Active Directory stores information about all trusted domains. Thus, you can find out all the trusted information about the domain simply by looking at the Global Catalog and not being tied to the domain controller.
However, you need to know that even if domain information exists in Active Directory, this does not mean that you can bind to it. Perhaps you do not have the rights to bind to it or the firewall settings in your environment may block your access to some domains.
Here I assume the following.
- The computer on which your software is running is already connected to the domain.
- You register as a domain user when you start the software.
- You have only one forest, but the forest includes many domains.
- You have a global catalog in your forest (very often you have one)
- You enter a DNS domain name, but not a NETBIOS domain name
You can use the following code to check if a domain exists in your current forest. If so, continue calling Domain.GetDomain (context) to get the Domain object. If for some reason you cannot get attached to it, you still need to wait until the timeout occurs.
private bool DomainExist(string domain) { HashSet<string> domains = new HashSet<string>(); foreach (Domain d in Forest.GetCurrentForest().Domains) { domains.Add(d.Name.ToLower()); } return domains.Contains(domain.ToLower()); }
source share