HttpListener.AuthenticationSchemeSelectorDelegate プロパティ

定義

クライアントの認証に使用するプロトコルを確認するために呼び出されるデリゲートを取得または設定します。

public:
 property System::Net::AuthenticationSchemeSelector ^ AuthenticationSchemeSelectorDelegate { System::Net::AuthenticationSchemeSelector ^ get(); void set(System::Net::AuthenticationSchemeSelector ^ value); };
public System.Net.AuthenticationSchemeSelector? AuthenticationSchemeSelectorDelegate { get; set; }
public System.Net.AuthenticationSchemeSelector AuthenticationSchemeSelectorDelegate { get; set; }
member this.AuthenticationSchemeSelectorDelegate : System.Net.AuthenticationSchemeSelector with get, set
Public Property AuthenticationSchemeSelectorDelegate As AuthenticationSchemeSelector

プロパティ値

認証プロトコルの選択に使用されるメソッドを呼び出す AuthenticationSchemeSelector デリゲート。 既定値は null です。

例外

このオブジェクトは閉じられました。

次のコード例では、このプロパティの値を設定します。

// Set up a listener.
HttpListener listener = new HttpListener();
HttpListenerPrefixCollection prefixes = listener.Prefixes;
prefixes.Add(@"http://localhost:8080/");
prefixes.Add(@"http://contoso.com:8080/");

// Specify the authentication delegate.
listener.AuthenticationSchemeSelectorDelegate =
    new AuthenticationSchemeSelector (AuthenticationSchemeForClient);

// Start listening for requests and process them
// synchronously.
listener.Start();
' Set up a listener.
Dim listener As New HttpListener()
Dim prefixes As HttpListenerPrefixCollection = listener.Prefixes
prefixes.Add("http://localhost:8080/")
prefixes.Add("http://contoso.com:8080/")

' Specify the authentication delegate.
listener.AuthenticationSchemeSelectorDelegate = New AuthenticationSchemeSelector(AddressOf AuthenticationSchemeForClient)

' Start listening for requests and process them 
' synchronously.
listener.Start()

次のコード例では、デリゲートによって呼び出されるメソッドの実装を AuthenticationSchemeSelector 示します。

static AuthenticationSchemes AuthenticationSchemeForClient(HttpListenerRequest request)
{
    Console.WriteLine("Client authentication protocol selection in progress...");
    // Do not authenticate local machine requests.
    if (request.RemoteEndPoint.Address.Equals (IPAddress.Loopback))
    {
        return AuthenticationSchemes.None;
    }
    else
    {
        return AuthenticationSchemes.IntegratedWindowsAuthentication;
    }
}
Private Shared Function AuthenticationSchemeForClient(ByVal request As HttpListenerRequest) As AuthenticationSchemes
    Console.WriteLine("Client authentication protocol selection in progress...")
    ' Do not authenticate local machine requests.
    If request.RemoteEndPoint.Address.Equals(IPAddress.Loopback) Then
        Return AuthenticationSchemes.None
    Else
        Return AuthenticationSchemes.IntegratedWindowsAuthentication
    End If
End Function

注釈

Note

の特定のインスタンス HttpListenerによって処理されるすべての要求に同じ認証プロトコルを使用する場合は、このプロパティを設定する必要はありません。 すべてのクライアント要求に使用するプロトコルを指定するには、 プロパティを AuthenticationSchemes 使用します。

クライアントがヘッダーに認証情報を指定していない場合、 HttpListener は認証されていない受信要求ごとに指定されたデリゲートを呼び出して、クライアントの認証に使用するプロトコル (存在する場合) を決定します。 メソッドと EndGetContext メソッドはGetContext、 が要求を正常に認証した場合HttpListenerにのみ、受信要求を返します。 要求を認証できない場合、 HttpListener は自動的に 401 応答を返します。 プロパティを使用して、正常に認証されたクライアントの ID を HttpRequest.LogonUserIdentity 取得できます。

認証プロトコルの選択をアプリケーション固有の方法に委任する機能は、 のHttpListenerインスタンスで、受信する要求の特性 (要求の プロパティUserHostAddressなど) に応じて異なる認証プロトコルをUrl使用する場合に便利です。

Note

ダイジェスト、NTLM、またはネゴシエートを有効にするようにこのプロパティを設定するには、 がControlPrincipal必要SecurityPermissionです。

適用対象