HttpListener.AuthenticationSchemes Propiedad

Definición

Obtiene o establece el esquema utilizado para autenticar los clientes.

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

Valor de propiedad

Una combinación bit a bit de valores de la enumeración AuthenticationSchemes que indica cómo serán autenticados los clientes. El valor predeterminado es Anonymous.

Excepciones

Este objeto se ha cerrado.

Ejemplos

En el ejemplo de código siguiente se muestra el uso de la AuthenticationSchemes propiedad para especificar un esquema de autenticación.

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

Comentarios

HttpListener utiliza el esquema especificado para autenticar todas las solicitudes entrantes. Los GetContext métodos y EndGetContext devuelven una solicitud de cliente entrante solo si la HttpListener autentica correctamente.

Puede interrogar la identidad de un cliente autenticado correctamente mediante la HttpListenerContext.User propiedad .

Si desea que un HttpListener objeto use distintos mecanismos de autenticación en función de las características de las solicitudes que recibe (por ejemplo, la propiedad o UserHostName la solicitudUrl), debe implementar un método que elija el esquema de autenticación. Para obtener instrucciones sobre cómo hacerlo, consulte la documentación de la AuthenticationSchemeSelectorDelegate propiedad.

Nota

Para establecer esta propiedad para habilitar Digest, NTLM o Negotiate requiere SecurityPermission, ControlPrincipal.

Se aplica a