AuthenticationSchemeSelector 代理人

定義

HttpListener インスタンスの認証方式を選択します。

public delegate System::Net::AuthenticationSchemes AuthenticationSchemeSelector(HttpListenerRequest ^ httpRequest);
public delegate System.Net.AuthenticationSchemes AuthenticationSchemeSelector(HttpListenerRequest httpRequest);
type AuthenticationSchemeSelector = delegate of HttpListenerRequest -> AuthenticationSchemes
Public Delegate Function AuthenticationSchemeSelector(httpRequest As HttpListenerRequest) As AuthenticationSchemes 

パラメーター

httpRequest
HttpListenerRequest

認証方式の選択対象となる HttpListenerRequest インスタンス。

戻り値

指定したクライアント要求に使用する認証のメソッドを示す AuthenticationSchemes 値の 1 つ。

次の例では、この型のインスタンスを使用して プロパティを AuthenticationSchemeSelectorDelegate 設定します。

// 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

注釈

この型のデリゲートは、要求の特性に基づいて認証スキームを選択するためにインスタンスによって HttpListener 使用されます。

AuthenticationSchemeSelectorデリゲートには、認証情報をHttpListenerRequest提供していない受信要求ごとに オブジェクトが渡されます。 デリゲートによって呼び出されるメソッドは、 オブジェクトとその他の HttpListenerRequest 使用可能な情報を使用して、必要な認証スキームを決定します。 デリゲートは、 プロパティを使用 AuthenticationSchemeSelectorDelegate して指定します。

拡張メソッド

GetMethodInfo(Delegate)

指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。

適用対象