AuthenticationSchemeSelector 委托

定义

HttpListener 实例选择身份验证方案。Selects the authentication scheme for an HttpListener instance.

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 实例。The HttpListenerRequest instance for which to select an authentication scheme.

返回值

AuthenticationSchemes

AuthenticationSchemes 值之一,指示要用于指定的客户端请求的身份验证方法。One of the AuthenticationSchemes values that indicates the method of authentication to use for the specified client request.

继承
AuthenticationSchemeSelector

示例

下面的示例使用此类型的实例来设置 AuthenticationSchemeSelectorDelegate 属性。The following example uses an instance of this type to set the AuthenticationSchemeSelectorDelegate property.

// 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 委托调用的方法的实现。The following example shows the implementation of the method invoked by the AuthenticationSchemeSelector delegate in the previous example.

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 实例使用此类型的委托根据请求的特征选择身份验证方案。Delegates of this type are used by HttpListener instances to select an authentication scheme based on the characteristics of a request.

为每个未提供身份验证信息的传入请求 HttpListenerRequest 传递一个 AuthenticationSchemeSelector 委托。An AuthenticationSchemeSelector delegate is passed an HttpListenerRequest object for each incoming request that has not provided authentication information. 委托调用的方法使用 HttpListenerRequest 对象和任何其他可用信息来确定所需的身份验证方案。The method invoked by the delegate uses the HttpListenerRequest object and any other available information to decide which authentication scheme to require. 委托是使用 AuthenticationSchemeSelectorDelegate 属性指定的。The delegate is specified by using the AuthenticationSchemeSelectorDelegate property.

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

适用于