Query : My project home page should have list of domain controllers as of now for one selected forest with a specified domain example.com , with + sign, if we expand + sign, we should be able to see LIST OF CONNECTED replicated servers in each DC for each domain.

How to pull this content using -

MVC3 ( what elements involve in model,what could be in controller, view... etc) Rajor C#

AccountManagement Namespace

to be more specific

display the same thing for every DC in the current domain (exmple.com)

to be more clear :

example.com is domain let i say we have 4 domain controllers DC1 DC2 DC3 DC4

Inturn DC1 will have replicated DCs like under DC1 e will have sub DC1 server1 sub DC1 server2

etc

under DC2 we will have

sub DC2 server1 sub DC2 Server2

I have tried till now as a newbie : created a home page in MVC3 where a header and footer is placed with some rough data. In Body section im strucked in providing the treeview like file explorer with domain controllers list in a domain.

Thanks in advance.

有帮助吗?

解决方案

Here is you solution

After searching for so long MSDN documentation I got your solution.

I think this is what you are expecting.

ArrayList alDcs = new ArrayList();
Domain domainaa = Domain.GetCurrentDomain();
foreach (DomainController dc in domainaa.DomainControllers)
 {
    alDcs.Add(dc.Name);
 }

GetCurrentDomain method is determined by the domain credentials under which the application is running. To retrieve the Domain object representing the domain to which the computer running the application is joined, regardless of the credentials associated with that application, use the GetComputerDomainmethod instead.

In this way I can get all of the Domain Controller which have already mantain theri Trust Relationship with each other.

There is another way where you can give credential of the Users which have Administrator Rights.

  ArrayList alDomains = new ArrayList();
  Forest currentForest = Forest.GetForest(new DirectoryContext(DirectoryContextType.Forest, "contesso.local", "userame", "password"));
  DomainCollection myDomains = currentForest.Domains;
  DomainControllerCollection dccc = currentForest.RootDomain.DomainControllers;
  foreach (DomainController dc in dccc)
    {
       alDomains.Add(dc.Name);
    }

Now the Only part is left to create a Tree View that I guess you can do yourself.

Hope this helps you

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top