AuthenticationSchemeSelector Delegát

Definice

Vybere schéma ověřování pro HttpListener instanci.

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

Instance HttpListenerRequest , pro kterou chcete vybrat schéma ověřování.

Návratová hodnota

AuthenticationSchemes

Jedna z AuthenticationSchemes hodnot, která označuje metodu ověřování, která se má použít pro zadaný požadavek klienta.

Příklady

Následující příklad používá instanci tohoto typu k nastavení AuthenticationSchemeSelectorDelegate vlastnosti.

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

Následující příklad ukazuje implementaci metody vyvolané delegátem AuthenticationSchemeSelector v předchozím příkladu.

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

Poznámky

Delegáti tohoto typu používají HttpListener instance k výběru schématu ověřování na základě charakteristik požadavku.

Delegát AuthenticationSchemeSelector se předá HttpListenerRequest objekt pro každý příchozí požadavek, který nezadá ověřovací informace. Metoda vyvolaná delegátem používá HttpListenerRequest objekt a všechny další dostupné informace k rozhodnutí, které schéma ověřování má vyžadovat. Delegát je určen pomocí AuthenticationSchemeSelectorDelegate vlastnosti.

Metody rozšíření

GetMethodInfo(Delegate)

Získá objekt, který představuje metodu reprezentovanou zadaným delegátem.

Platí pro