HttpListener.UnsafeConnectionNtlmAuthentication Propriedade

Definição

Obtém ou define um valor Boolean que controla se, ao usar o NTLM, solicitações adicionais usando a mesma conexão por protocolo TCP são ou não necessárias para autenticação.

public:
 property bool UnsafeConnectionNtlmAuthentication { bool get(); void set(bool value); };
public bool UnsafeConnectionNtlmAuthentication { get; set; }
member this.UnsafeConnectionNtlmAuthentication : bool with get, set
Public Property UnsafeConnectionNtlmAuthentication As Boolean

Valor da propriedade

true se o IIdentity da primeira solicitação for usado para solicitações subsequentes na mesma conexão; caso contrário, false. O valor padrão é false.

Exceções

Este objeto foi fechado.

Exemplos

O exemplo de código a seguir demonstra a configuração dessa propriedade.

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

Comentários

Quando essa propriedade é definida como true e a primeira solicitação em uma conexão TCP específica é autenticada usando NTLM, as solicitações subsequentes na mesma conexão TCP são processadas usando as informações de autenticação (IIdentity) da solicitação inicial.

Essa propriedade não tem efeito quando NTLM não é o protocolo de autenticação. Quando Negotiate é especificado como o protocolo de autenticação, essa propriedade só terá efeito se NTLM for o protocolo real usado para autenticação.

Observação

Ao definir essa propriedade para true aumentar o desempenho porque o HttpListener não envia desafios adicionais de autenticação NTLM, há um risco de segurança em não exigir que todas as solicitações forneçam informações de autenticação. Você deve determinar se o aumento no desempenho vale esse risco.

Aplica-se a