次の方法で共有


Binding Strings

The following examples show how to bind to different types of objects in the directory. The binding strings in this topic use the syntax for an LDAP service provider, which is used to bind to Active Directory and other LDAP directory objects. The binding string is called an ADsPath.

Binding to the current domain

For most client applications, bind to the domain that provides authentication for the user. The following examples show this type of binding.

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

Binding to a specific server

The following examples show how to bind to a specific server by adding the server name to your ADsPath.

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

Binding to a specific domain

The following examples show how to add the domain name to the ADsPath to bind to a specific domain.

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

Binding to a specific object

To modify or read data from a specific object, bind to that object by adding its relative distinguished name (RDN) to the binding string. In the following examples, the binding point is on the user object 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");

Binding using an alternate credential

The following example shows how to use a user name and password that are passed from a user interface as credentials to bind to a 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);

Binding using flags

The following example shows how to specify alternate binding options using the AuthenticationType property. Prior to .NET Framework 2.0, the default value for AuthenticationType is None. Beginning with .NET Framework 2.0, the default value is 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);

To clear the memory before the application leaves the scope, call the Dispose method on the bound object.

See Also

Reference

System.DirectoryServices
DirectoryEntry
AuthenticationTypes

Concepts

Binding to Directory Objects

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.