英語で読む

次の方法で共有


AuthenticationSchemeSelector 代理人

定義

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

C#
public delegate System.Net.AuthenticationSchemes AuthenticationSchemeSelector(HttpListenerRequest httpRequest);

パラメーター

httpRequest
HttpListenerRequest

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

戻り値

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

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

C#
// 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();

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

C#
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;
    }
}

注釈

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

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

拡張メソッド

GetMethodInfo(Delegate)

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

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1