閱讀英文版本

分享方式:


AuthenticationSchemeSelector 代理人

定義

選取 HttpListener 執行個體的驗證配置。

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

參數

httpRequest
HttpListenerRequest

要選取驗證配置的 HttpListenerRequest 執行個體。

傳回值

其中一個 AuthenticationSchemes 值,指出要用於指定用戶端要求的驗證方法。

範例

下列範例會使用這個類型的實例來設定 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