Stringhe di associazione

Negli esempi riportati di seguito viene illustrato come eseguire l'associazione a diversi tipi di oggetti nella directory. Le stringhe di associazione in questo argomento utilizzano la sintassi di un provider di servizi LDAP che viene utilizzata per associare Active Directory e altri oggetti directory LDAP. La stringa di associazione è detta ADsPath.

Associazione al dominio corrente

Per la maggior parte delle applicazioni, eseguire l'associazione al dominio che fornisce l'autenticazione per l'utente. Negli esempi riportati di seguito viene illustrato questo tipo di associazione.

Dim ent As New DirectoryEntry()
DirectoryEntry ent = new DirectoryEntry();

Associazione a un server specifico

Negli esempi riportati di seguito viene illustrato come eseguire l'associazione a un server specifico aggiungendo il nome del server a ADsPath.

Dim ent As New DirectoryEntry("LDAP://server01")
DirectoryEntry ent = new DirectoryEntry("LDAP://server01");

Associazione a un dominio specifico

Negli esempi riportati di seguito viene illustrato come aggiungere il nome del dominio a ADsPath per eseguire l'associazione a un dominio specifico.

Dim ent As New DirectoryEntry("LDAP://platform.fabrikam.com")
DirectoryEntry ent = new DirectoryEntry("LDAP://platform.fabrikam.com");

Associazione a un oggetto specifico

Per modificare o leggere i dati di un oggetto specifico, eseguire l'associazione a quell'oggetto aggiungendo il nome distinto relativo (RDN) alla stringa di associazione. Negli esempi riportati di seguito il punto di associazione è l'oggetto utente Jeff Smith.

' If the object is on the domain that you are connected to, use this statment.
Dim ent As New DirectoryEntry("LDAP://CN=Jeff Smith,OU=Marketing,DC=fabrikam,DC=Com")
' If you know the server where the object is located, and you want to reduce search hits, use this statement.
Dim ent As New DirectoryEntry("LDAP://server01/CN=Jeff Smith,OU=Marketing,DC=fabrikam,DC=Com")
' To search a specific domain for this object, use this statement.
Dim ent As New DirectoryEntry("LDAP://fabrikam.com/CN=Jeff Smith,OU=Marketing,DC=fabrikam,DC=Com")
// If the object is on the domain that you are connected to, use this statment.
DirectoryEntry ent = new DirectoryEntry("LDAP://CN=Jeff Smith,OU=Marketing,DC=fabrikam,DC=Com");
// If you know the server where the object is located, to reduce search hits, use this statement.
DirectoryEntry ent = new DirectoryEntry("LDAP://server01/CN=Jeff Smith,OU=Marketing,DC=fabrikam,DC=Com");
// To search a specific domain for this object, use this statement.
DirectoryEntry ent = new DirectoryEntry("LDAP://fabrikam.com/CN=Jeff Smith,OU=Marketing,DC=fabrikam,DC=Com");

Associazione utilizzando credenziali alternative

Nell'esempio riportato di seguito viene illustrato come utilizzare un nome utente e una password passati dall'interfaccia utente come credenziali per eseguire l'associazione a un server.

' GetUserNameFromUI() and GetPasswordFromUI() are functions created to pass in data.
Dim userName As [String] = GetUserNameFromUI()
Dim password As String = GetPasswordFromUI()
Dim ent As New DirectoryEntry("LDAP://server01", userName, password)
// GetUserNameFromUI() and GetPasswordFromUI() are functions created to pass in data.
String userName = GetUserNameFromUI();
string password = GetPasswordFromUI();
DirectoryEntry ent = new DirectoryEntry("LDAP://server01", userName, password);

Associazione utilizzando flag

Nell'esempio riportato di seguito viene illustrato come specificare opzioni di associazione alternativa utilizzando la proprietà AuthenticationType. Prima di .NET Framework 2.0, il valore predefinito per AuthenticationType è None. A partire da .NET Framework 2.0, il valore predefinito è Secure.

Dim ent As New DirectoryEntry("LDAP://server01", Nothing, Nothing, AuthenticationTypes.ServerBind Or AuthenticationTypes.FastBind)
DirectoryEntry ent = new DirectoryEntry("LDAP://server01",null,null,AuthenticationTypes.ServerBind | AuthenticationTypes.FastBind);

Per cancellare il contenuto della memoria prima che l'applicazione esca dall'ambito, chiamare il metodo Dispose per l'oggetto associato.

Vedere anche

Riferimenti

System.DirectoryServices
DirectoryEntry
AuthenticationTypes

Concetti

Associazione agli oggetti directory

Send comments about this topic to Microsoft.

Copyright © 2007 Microsoft Corporation. Tutti i diritti riservati.