2015-04-13 8 views
5

Ich habe eine Zeit lang in dieser und ich bin immer immer:So stellen Sie eine Verbindung zu Active Directory mit dem Hauptkontext her?

System.DirectoryServices.AccountManagement.PrincipalServerDownException

Was ich denke, bedeutet mein Verbindungsaufbau (Connection String) falsch ist .

Wenn ich "dsquery Server" auf cmd auf dem Computer schreiben, wo das Active Directory ist, erhalte ich:

„CN = DCESTAGIO, CN = Server CN = Default-First-Site-Name, CN = Sites, CN = Configuration, DC = estagioit, DC = local“

ich folgendes Verbinden auf folgende Weise versucht haben:

1:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "192.168.56.101", "DC=estagioit,DC=local"); 

2:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "192.168.56.101/DC=estagioit,DC=local"); 

3:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "192.168.56.101/CN=DCESTAGIO,DC=estagioit,DC=local"); 

4:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "192.168.56.101/CN=DCESTAGIO,CN=SERVERS,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=estagioit,DC=local"); 

5:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "LDAP://192.168.56.101/CN=Users,DC=estagioit,DC=local"); 

Und einige andere Möglichkeiten ...

Irgendwelche Ideen, was falsch ist und wie ich diese Verbindung herstellen kann?

PS: Die IP ist korrekt gesehen, wie ich es zum Pingen verwendet habe und es funktioniert.

PSS: Ich brauche das wirklich so schnell wie möglich, wenn Sie irgendwelche Vorschläge haben, sind sie alle willkommen.

Antwort

15

Wenn Sie bei der Dokumentation suchen die PrincipalContext Bauer, sollte es ganz klar zu sagen:

public PrincipalContext(ContextType contextType, string name) 

oder

public PrincipalContext(ContextType contextType, string name, string container) 

Sie müssen also im Grunde:

  • Ihre Kontextart (hier: ContextType.Domain)
  • der Domänenname (versuchen Sie nur den Namen "Netbios", z.„YOURDOMAIN“ - oder für „default“ Domain NULL verlassen)
  • optional einen Behälter (als LDAP-Pfad - ein „ausgezeichneter“ Namen, vollständiger Pfad aber ohne LDAP:// Präfix)

So etwas wie dies versucht, :

PrincipalContext thisPrincipalContext = 
    new PrincipalContext(ContextType.Domain, "ESTAGIOIT"); 

oder

PrincipalContext thisPrincipalContext = 
    new PrincipalContext(ContextType.Domain, null); // default domain 

oder

PrincipalContext thisPrincipalContext = 
    new PrincipalContext(ContextType.Domain, "ESTAGIOIT", "DC=estagioit,DC=local"); 

oder

PrincipalContext thisPrincipalContext = 
    new PrincipalContext(ContextType.Domain, null, "CN=Users,DC=estagioit,DC=local"); 
+0

Dank du hast mich gerettet wirklich ein Mann! ;) –

+0

Ich habe eine relevante Frage. Ich hoffe du kannst mir helfen: http://stackoverflow.com/questions/42971315/finding-active-directory-users-from-2-ou – user2931442

Verwandte Themen