AuthenticationSchemeSelector AuthenticationSchemeSelector AuthenticationSchemeSelector AuthenticationSchemeSelector Delegate

Definizione

Seleziona lo schema di autenticazione per un'istanza di 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 

Parametri

httpRequest
HttpListenerRequest HttpListenerRequest HttpListenerRequest HttpListenerRequest

Istanza di HttpListenerRequest per la quale selezionare uno schema di autenticazione.The HttpListenerRequest instance for which to select an authentication scheme.

Valore restituito

System.Net.AuthenticationSchemes

Uno dei valori AuthenticationSchemes che indicano il metodo di autenticazione da utilizzare per la richiesta del client specificata.One of the AuthenticationSchemes values that indicates the method of authentication to use for the specified client request.

Ereditarietà
AuthenticationSchemeSelectorAuthenticationSchemeSelectorAuthenticationSchemeSelectorAuthenticationSchemeSelector

Esempi

Nell'esempio seguente viene utilizzata un'istanza di questo tipo per impostare AuthenticationSchemeSelectorDelegate la proprietà.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()

Nell'esempio seguente viene illustrata l'implementazione del metodo richiamato AuthenticationSchemeSelector dal delegato nell'esempio precedente.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

Commenti

I delegati di questo tipo HttpListener vengono usati dalle istanze per selezionare uno schema di autenticazione in base alle caratteristiche di una richiesta.Delegates of this type are used by HttpListener instances to select an authentication scheme based on the characteristics of a request.

A AuthenticationSchemeSelector un delegato viene passato HttpListenerRequest un oggetto per ogni richiesta in ingresso che non ha fornito informazioni di autenticazione.An AuthenticationSchemeSelector delegate is passed an HttpListenerRequest object for each incoming request that has not provided authentication information. Il metodo richiamato dal delegato usa l' HttpListenerRequest oggetto e qualsiasi altra informazione disponibile per decidere quale schema di autenticazione richiedere.The method invoked by the delegate uses the HttpListenerRequest object and any other available information to decide which authentication scheme to require. Il delegato viene specificato tramite la AuthenticationSchemeSelectorDelegate proprietà.The delegate is specified by using the AuthenticationSchemeSelectorDelegate property.

Metodi di estensione

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

Ottiene un oggetto che rappresenta il metodo rappresentato dal delegato specificato.Gets an object that represents the method represented by the specified delegate.

Si applica a