Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

AuthenticationSchemeSelector Delegate

Selects the authentication scheme for an HttpListener instance.

Namespace: System.Net
Assembly: System (in system.dll)

public delegate AuthenticationSchemes AuthenticationSchemeSelector (
	HttpListenerRequest httpRequest
)
/** @delegate */
public delegate AuthenticationSchemes AuthenticationSchemeSelector (
	HttpListenerRequest httpRequest
)
Not applicable.

Parameters

httpRequest

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.

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.
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();

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;
    }
}

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.