AuthenticationSchemeSelector Delegato

Definizione

Seleziona lo schema di autenticazione per un'istanza di HttpListener.

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 

Parametri

httpRequest
HttpListenerRequest

Istanza di HttpListenerRequest per la quale selezionare uno schema di autenticazione.

Valore restituito

AuthenticationSchemes

Uno dei valori AuthenticationSchemes che indicano il metodo di autenticazione da utilizzare per la richiesta del client specificata.

Esempio

Nell'esempio seguente viene usata un'istanza di questo tipo per impostare la AuthenticationSchemeSelectorDelegate proprietà.

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

Nell'esempio seguente viene illustrata l'implementazione del metodo richiamato dal AuthenticationSchemeSelector delegato nell'esempio precedente.

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

Commenti

I delegati di questo tipo vengono usati dalle HttpListener istanze per selezionare uno schema di autenticazione in base alle caratteristiche di una richiesta.

Un AuthenticationSchemeSelector delegato viene passato un HttpListenerRequest oggetto per ogni richiesta in ingresso che non ha fornito informazioni di autenticazione. Il metodo richiamato dal delegato usa l'oggetto HttpListenerRequest e qualsiasi altra informazione disponibile per decidere quale schema di autenticazione richiedere. Il delegato viene specificato usando la AuthenticationSchemeSelectorDelegate proprietà .

Metodi di estensione

GetMethodInfo(Delegate)

Ottiene un oggetto che rappresenta il metodo rappresentato dal delegato specificato.

Si applica a