Cadenas de enlace

En los siguientes ejemplos se muestra cómo enlazar con diferentes tipos de objetos del directorio. Las cadenas de enlace de este tema usan la sintaxis de un proveedor de servicios LDAP, utilizado para enlazar con objetos de Active Directory y otros objetos de directorio LDAP. La cadena de enlace se denomina ADsPath.

Enlazar con el dominio actual

En el caso de la mayoría de aplicaciones cliente, debe enlazar con el dominio que proporcione la autenticación del usuario. En los siguientes ejemplos se muestra este tipo de enlace.

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

Enlazar con un servidor específico

Los siguientes ejemplos muestran cómo enlazar con un servidor específico agregando el nombre de servidor a ADsPath.

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

Enlazar con un dominio específico

En los siguientes ejemplos se muestra cómo agregar el nombre de dominio a ADsPath para enlazar con un dominio específico.

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

Enlazar con un objeto específico

Para modificar o leer datos de un objeto específico, enlace con ese objeto agregando su nombre distintivo relativo (RDN) a la cadena de conexión. En los siguientes ejemplos, el punto de enlace se encuentra en el objeto de usuario 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");

Enlazar mediante una credencial alternativa

En el siguiente ejemplo se muestra cómo utilizar un nombre de usuario y una contraseña que se pasan desde una interfaz de usuario como credenciales para enlazar con un servidor.

' 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);

Enlazar mediante indicadores

En el siguiente ejemplo se muestra cómo especificar opciones de enlace alternativas mediante la propiedad AuthenticationType. Antes de .NET Framework 2.0, el valor predeterminado de AuthenticationType es None. A partir de .NET Framework 2.0, el valor predeterminado es 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);

Para borrar la memoria antes de que la aplicación abandone el ámbito, llame al método Dispose del objeto enlazado.

Consulte también

Referencia

System.DirectoryServices
DirectoryEntry
AuthenticationTypes

Conceptos

Enlazar con objetos de directorio

Send comments about this topic to Microsoft.

Copyright © 2007 Microsoft Corporation. Reservados todos los derechos.