次の方法で共有


バインド文字列

次の例は、ディレクトリ内のさまざまな種類のオブジェクトにバインドする方法を示しています。このトピックのバインド文字列は、LDAP サービス プロバイダの構文を使用します。LDAP サービス プロバイダは、Active Directory および他の LDAP ディレクトリ オブジェクトへのバインドに使用されます。バインド文字列は ADsPath と呼ばれます。

現在のドメインへのバインド

大部分のクライアント アプリケーションでは、ユーザーの認証を提供するドメインにバインドします。次の例は、この種類のバインドを示しています。

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

特定のサーバーへのバインド

次の例は、ADsPath にサーバー名を追加することによって、特定のサーバーにバインドする方法を示しています。

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

特定のドメインへのバインド

次の例は、ADsPath にドメイン名を追加して、特定のドメインにバインドする方法を示しています。

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

特定のオブジェクトへのバインド

特定のオブジェクトのデータを変更するまたは読み取るには、その相対識別名 (RDN : Relative Distinguished Name) をバインド文字列に追加することによって、そのオブジェクトにバインドします。次の例では、バインド ポイントはユーザー オブジェクト 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");

別の資格情報を使用したバインド

次の例は、資格情報としてユーザー インターフェイスから渡されるユーザー名とパスワードを使用して、サーバーにバインドする方法を示しています。

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

フラグを使用したバインド

次の例は、AuthenticationType プロパティを使用して、別のバインド オプションを指定する方法を示しています。.NET Framework 2.0 より前は、AuthenticationType に対する既定値は None です。.NET Framework 2.0 以降は、既定値は 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);

アプリケーションがスコープから出る前にメモリをクリアするには、バインドされたオブジェクトで Dispose メソッドを呼び出します。

関連項目

リファレンス

System.DirectoryServices
DirectoryEntry
AuthenticationTypes

概念

ディレクトリ オブジェクトへのバインド

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.