HttpListener.AuthenticationSchemeSelectorDelegate Proprietà

Definizione

Ottiene o imposta il delegato chiamato per determinare il protocollo usato per autenticare i client.

public:
 property System::Net::AuthenticationSchemeSelector ^ AuthenticationSchemeSelectorDelegate { System::Net::AuthenticationSchemeSelector ^ get(); void set(System::Net::AuthenticationSchemeSelector ^ value); };
public System.Net.AuthenticationSchemeSelector? AuthenticationSchemeSelectorDelegate { get; set; }
public System.Net.AuthenticationSchemeSelector AuthenticationSchemeSelectorDelegate { get; set; }
member this.AuthenticationSchemeSelectorDelegate : System.Net.AuthenticationSchemeSelector with get, set
Public Property AuthenticationSchemeSelectorDelegate As AuthenticationSchemeSelector

Valore della proprietà

Delegato AuthenticationSchemeSelector che richiama il metodo usato per selezionare un protocollo di autenticazione. Il valore predefinito è null.

Eccezioni

L'oggetto è stato chiuso.

Esempio

Nell'esempio di codice seguente viene impostato il valore di questa 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 di codice seguente viene fornita un'implementazione di un metodo richiamato da un AuthenticationSchemeSelector delegato.

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

Nota

Se si vuole usare lo stesso protocollo di autenticazione per tutte le richieste gestite da un'istanza specifica di HttpListener, non è necessario impostare questa proprietà. Per specificare un protocollo da usare per tutte le richieste client, usare la AuthenticationSchemes proprietà .

Se il client non ha specificato le informazioni di autenticazione nelle relative intestazioni, il HttpListener delegato specificato chiama il delegato specificato per ogni richiesta in ingresso non autenticata per determinare quale, se presente, protocollo da usare per autenticare il client. I GetContext metodi e EndGetContext restituiscono una richiesta in ingresso solo se la HttpListener richiesta è stata autenticata correttamente. Se non è possibile autenticare una richiesta, la HttpListener risposta restituisce automaticamente una risposta 401. È possibile ottenere l'identità di un client autenticato correttamente usando la HttpRequest.LogonUserIdentity proprietà .

La possibilità di delegare la scelta del protocollo di autenticazione a un metodo specifico dell'applicazione è utile se si vuole che un'istanza Url di usi protocolli di HttpListener autenticazione diversi a seconda delle caratteristiche delle richieste ricevute(ad esempio, la proprietà o UserHostAddress la richiesta).

Nota

Per impostare questa proprietà per abilitare Digest, NTLM o Negotiate richiede , SecurityPermissionControlPrincipal.

Si applica a