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

HttpListener.AuthenticationSchemeSelectorDelegate Property

Gets or sets the delegate called to determine the protocol used to authenticate clients.

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

'Declaration
Public Property AuthenticationSchemeSelectorDelegate As AuthenticationSchemeSelector
'Usage
Dim instance As HttpListener
Dim value As AuthenticationSchemeSelector

value = instance.AuthenticationSchemeSelectorDelegate

instance.AuthenticationSchemeSelectorDelegate = value
/** @property */
public AuthenticationSchemeSelector get_AuthenticationSchemeSelectorDelegate ()

/** @property */
public void set_AuthenticationSchemeSelectorDelegate (AuthenticationSchemeSelector value)

public function get AuthenticationSchemeSelectorDelegate () : AuthenticationSchemeSelector

public function set AuthenticationSchemeSelectorDelegate (value : AuthenticationSchemeSelector)

Not applicable.

Property Value

An AuthenticationSchemeSelector delegate that invokes the method used to select an authentication protocol. The default value is a null reference (Nothing in Visual Basic).
Exception typeCondition

ObjectDisposedException

This object has been closed.

NoteNote:

If you want the same authentication protocol to be used for all requests handled by a particular instance of HttpListener, you do not need to set this property. To specify a protocol to be used for all client requests, use the AuthenticationSchemes property.

If the client has not specified authentication information in its headers, the HttpListener calls the specified delegate for each unauthenticated incoming request to determine which, if any, protocol to use to authenticate the client. The GetContext and EndGetContext methods return an incoming request only if the HttpListener successfully authenticated the request. If a request cannot be authenticated, the HttpListener automatically sends back a 401 response. You can get the identity of a successfully authenticated client using the HttpRequest.LogonUserIdentity property.

The ability to delegate the choice of authentication protocol to an application-specific method is useful if you want an instance of HttpListener to use different authentication protocols depending on the characteristics of the requests it receives (for example, the request's Url or UserHostAddress property).

NoteNote:

To set this property to enable Digest, NTLM, or Negotiate requires the SecurityPermission, ControlPrincipal.

The following code example sets the value of this 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 code example provides an implementation of a method invoked by an AuthenticationSchemeSelector delegate.

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 2003, Windows XP Media Center 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.