AuthenticationSchemeSelector Delegera

Definition

Väljer autentiseringsschemat för en HttpListener instans.

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 

Parametrar

httpRequest
HttpListenerRequest

Den HttpListenerRequest instans som du vill välja ett autentiseringsschema för.

Returvärde

Ett av de AuthenticationSchemes värden som anger vilken autentiseringsmetod som ska användas för den angivna klientbegäran.

Exempel

I följande exempel används en instans av den här typen för att ange AuthenticationSchemeSelectorDelegate egenskapen.

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

I följande exempel visas implementeringen av metoden som anropades av ombudet AuthenticationSchemeSelector i föregående exempel.

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

Kommentarer

Ombud av den här typen används av HttpListener instanser för att välja ett autentiseringsschema baserat på egenskaperna för en begäran.

Ett AuthenticationSchemeSelector ombud skickas ett HttpListenerRequest objekt för varje inkommande begäran som inte har angett autentiseringsinformation. Metoden som anropas av ombudet HttpListenerRequest använder objektet och annan tillgänglig information för att bestämma vilket autentiseringsschema som ska krävas. Ombudet anges med hjälp AuthenticationSchemeSelectorDelegate av egenskapen .

Tilläggsmetoder

Name Description
GetMethodInfo(Delegate)

Hämtar ett objekt som representerar den metod som representeras av det angivna ombudet.

Gäller för