AuthenticationSchemeSelector Delegate
Selects the authentication scheme for an HttpListener instance.
Assembly: System (in System.dll)
'Declaration Public Delegate Function AuthenticationSchemeSelector ( _ httpRequest As HttpListenerRequest _ ) As AuthenticationSchemes 'Usage Dim instance As New AuthenticationSchemeSelector(AddressOf HandlerMethod)
Parameters
- httpRequest
- Type: System.Net.HttpListenerRequest
The HttpListenerRequest instance for which to select an authentication scheme.
Return Value
Type: System.Net.AuthenticationSchemesOne of the AuthenticationSchemes values that indicates the method of authentication to use for the specified client request.
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.
The following example uses an instance of this type to set the AuthenticationSchemeSelectorDelegate property.
' 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.
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
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.