AuthenticationSchemeSelector Delegat

Definicja

Wybiera schemat uwierzytelniania dla HttpListener wystąpienia.

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 

Parametry

httpRequest
HttpListenerRequest

HttpListenerRequest Wystąpienie, dla którego należy wybrać schemat uwierzytelniania.

Wartość zwracana

AuthenticationSchemes Jedna z wartości wskazująca metodę uwierzytelniania do użycia dla określonego żądania klienta.

Przykłady

W poniższym przykładzie użyto wystąpienia tego typu, aby ustawić AuthenticationSchemeSelectorDelegate właściwość .

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

W poniższym przykładzie pokazano implementację metody wywoływanej przez delegata AuthenticationSchemeSelector w poprzednim przykładzie.

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

Uwagi

Delegaci tego typu są używane przez HttpListener wystąpienia do wybierania schematu uwierzytelniania na podstawie cech żądania.

Delegat AuthenticationSchemeSelector jest przekazywany HttpListenerRequest obiekt dla każdego przychodzącego żądania, które nie dostarczyło informacji uwierzytelniania. Metoda wywoływana przez delegata używa HttpListenerRequest obiektu i innych dostępnych informacji, aby zdecydować, który schemat uwierzytelniania ma być wymagany. Delegat jest określony przy użyciu AuthenticationSchemeSelectorDelegate właściwości .

Metody rozszerzania

GetMethodInfo(Delegate)

Pobiera obiekt reprezentujący metodę reprezentowaną przez określonego delegata.

Dotyczy