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