AuthenticationSchemeSelector Delegate
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Parameters
- httpRequest
- HttpListenerRequest
The HttpListenerRequest instance for which to select an authentication scheme.
Return Value
One of the AuthenticationSchemes values that indicates the method of authentication to use for the specified client request.
Examples
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()
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
Remarks
Delegates of this type are used by HttpListener instances to select an authentication scheme based on the characteristics of a request.
An AuthenticationSchemeSelector delegate is passed an HttpListenerRequest object for each incoming request that has not provided authentication information. The method invoked by the delegate uses the HttpListenerRequest object and any other available information to decide which authentication scheme to require. The delegate is specified by using the AuthenticationSchemeSelectorDelegate property.
Extension Methods
GetMethodInfo(Delegate) |
Gets an object that represents the method represented by the specified delegate. |
Applies to
Обратна връзка
https://aka.ms/ContentUserFeedback.
Очаквайте скоро: През цялата 2024 г. постепенно ще отстраняваме проблемите в GitHub като механизъм за обратна връзка за съдържание и ще го заменим с нова система за обратна връзка. За повече информация вижте:Подаване и преглед на обратна връзка за