HttpListener.AuthenticationSchemes HttpListener.AuthenticationSchemes HttpListener.AuthenticationSchemes HttpListener.AuthenticationSchemes Property

Définition

Obtient ou définit le schéma utilisé pour authentifier les clients.Gets or sets the scheme used to authenticate clients.

public:
 property System::Net::AuthenticationSchemes AuthenticationSchemes { System::Net::AuthenticationSchemes get(); void set(System::Net::AuthenticationSchemes value); };
public System.Net.AuthenticationSchemes AuthenticationSchemes { get; set; }
member this.AuthenticationSchemes : System.Net.AuthenticationSchemes with get, set
Public Property AuthenticationSchemes As AuthenticationSchemes

Valeur de propriété

Combinaison d'opérations de bits de valeurs d'énumération AuthenticationSchemes qui indiquent la manière dont les clients doivent être authentifiés.A bitwise combination of AuthenticationSchemes enumeration values that indicates how clients are to be authenticated. La valeur par défaut est Anonymous.The default value is Anonymous.

Exceptions

Exemples

L’exemple de code suivant montre comment utiliser le AuthenticationSchemes propriété pour spécifier un schéma d’authentification.The following code example demonstrates using the AuthenticationSchemes property to specify an authentication scheme.

public static void SimpleListenerWithUnsafeAuthentication(string[] prefixes)
{
    // URI prefixes are required,
    // for example "http://contoso.com:8080/index/".
    if (prefixes == null || prefixes.Length == 0)
      throw new ArgumentException("prefixes");
    // Set up a listener.
    HttpListener listener = new HttpListener();
    foreach (string s in prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    // Specify Negotiate as the authentication scheme.
    listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate;
    // If NTLM is used, we will allow multiple requests on the same
    // connection to use the authentication information of first request.
    // This improves performance but does reduce the security of your 
    // application. 
    listener.UnsafeConnectionNtlmAuthentication = true;
    // This listener does not want to receive exceptions 
    // that occur when sending the response to the client.
    listener.IgnoreWriteExceptions = true;
    Console.WriteLine("Listening...");
    // ... process requests here.

    listener.Close();
}
Public Shared Sub SimpleListenerWithUnsafeAuthentication(ByVal prefixes As String())
    ' URI prefixes are required,
    ' for example "http://contoso.com:8080/index/".
    If prefixes Is Nothing OrElse prefixes.Length = 0 Then Throw New ArgumentException("prefixes")
    ' Set up a listener.
    Dim listener As HttpListener = New HttpListener()

    For Each s As String In prefixes
        listener.Prefixes.Add(s)
    Next

    listener.Start()
    ' Specify Negotiate as the authentication scheme.
    listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate
    ' If NTLM Is used, we will allow multiple requests on the same
    ' connection to use the authentication information of first request.
    ' This improves performance but does reduce the security of your 
    ' application. 
    listener.UnsafeConnectionNtlmAuthentication = True
    ' This listener does Not want to receive exceptions 
    ' that occur when sending the response to the client.
    listener.IgnoreWriteExceptions = True
    Console.WriteLine("Listening...")
    ' ... process requests here.

    listener.Close()
End Sub

Remarques

Le HttpListener utilise le schéma spécifié pour authentifier toutes les demandes entrantes.The HttpListener uses the specified scheme to authenticate all incoming requests. Le GetContext et EndGetContext méthodes retournent une demande entrante du client uniquement si le HttpListener authentifie correctement la demande.The GetContext and EndGetContext methods return an incoming client request only if the HttpListener successfully authenticates the request.

Vous pouvez interroger l’identité d’un client correctement authentifié à l’aide de la HttpListenerContext.User propriété.You can interrogate the identity of a successfully authenticated client by using the HttpListenerContext.User property.

Si vous souhaitez un HttpListener objet à utiliser différents mécanismes d’authentification selon les caractéristiques des demandes qu’il reçoit (par exemple, de la demande Url ou UserHostName propriété), vous devez implémenter une méthode qui choisit le schéma d’authentification.If you want an HttpListener object to use different authentication mechanisms based on characteristics of the requests it receives (for example, the request's Url or UserHostName property), you must implement a method that chooses the authentication scheme. Pour savoir comment procéder, consultez la AuthenticationSchemeSelectorDelegate documentation de la propriété.For instructions about how to do this, see the AuthenticationSchemeSelectorDelegate property documentation.

Notes

Pour définir cette propriété pour activer Digest, NTLM ou Negotiate nécessite le SecurityPermission, ControlPrincipal.To set this property to enable Digest, NTLM, or Negotiate requires the SecurityPermission, ControlPrincipal.

S’applique à