Chaînes de liaison
Les exemples suivants montrent comment lier différents types d'objets dans l'annuaire. Dans cette rubrique, les chaînes de liaison utilisent la syntaxe pour un fournisseur de services LDAP, utilisé pour effectuer une liaison à Active Directory et à d'autres objets d'annuaire LDAP. La chaîne de liaison s'appelle ADsPath.
Liaison au domaine actuel
Pour la majorité des applications clientes, effectuez la liaison au domaine fournissant l'authentification à l'utilisateur. Les exemples suivants illustrent ce type de liaison.
Dim ent As New DirectoryEntry()
DirectoryEntry ent = new DirectoryEntry();
Liaison à un serveur spécifique
Les exemples suivants montrent comment effectuer une liaison à un serveur spécifique en ajoutant le nom du serveur à votre ADsPath.
Dim ent As New DirectoryEntry("LDAP://server01")
DirectoryEntry ent = new DirectoryEntry("LDAP://server01");
Liaison à un domaine spécifique
Les exemples suivants montrent comment ajouter le nom du domaine au ADsPath afin d'effectuer une liaison à un domaine spécifique.
Dim ent As New DirectoryEntry("LDAP://platform.fabrikam.com")
DirectoryEntry ent = new DirectoryEntry("LDAP://platform.fabrikam.com");
Liaison à un objet spécifique
Pour modifier ou lire des données depuis un objet spécifique, effectuez une liaison à cet objet en ajoutant son nom unique relatif à la chaîne de liaison. Dans les exemples suivants, le point de liaison se trouve sur l'objet utilisateur 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");
Liaison en utilisant une autre identité
L'exemple suivant montre comment utiliser un nom d'utilisateur et un mot de passe passés par une interface utilisateur comme informations d'identification afin d'effectuer une liaison à un serveur.
' 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);
Liaison à l'aide d'indicateurs
L'exemple suivant montre comment spécifier d'autres options de liaison en utilisant la propriété AuthenticationType. Avant .NET Framework 2.0, la valeur par défaut pour AuthenticationType est None. À partir de .NET Framework 2.0, la valeur par défaut est 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);
Pour effacer la mémoire avant que l'application ne soit hors de portée, appelez la méthode Dispose sur l'objet lié.
Voir aussi
Référence
System.DirectoryServices
DirectoryEntry
AuthenticationTypes
Concepts
Send comments about this topic to Microsoft.
Copyright © 2007 par Microsoft Corporation. Tous droits réservés.