HttpListener.UnsafeConnectionNtlmAuthentication 属性

定义

获取或设置 Boolean 值,该值控制当使用 NTLM 时是否需要对使用同一传输控制协议 (TCP) 连接的其他请求进行身份验证。Gets or sets a Boolean value that controls whether, when NTLM is used, additional requests using the same Transmission Control Protocol (TCP) connection are required to authenticate.

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

属性值

如果第一个请求的 IIdentity 将用于同一连接上的后续请求,则返回 true;否则返回 falsetrue if the IIdentity of the first request will be used for subsequent requests on the same connection; otherwise, false. 默认值为 falseThe default value is false.

例外

此对象已关闭。This object has been closed.

示例

下面的代码示例演示如何设置此属性。The following code example demonstrates setting this property.

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

注解

如果将此属性设置为 true,使用 NTLM 对特定 TCP 连接上的第一个请求进行身份验证,则将使用初始请求的身份验证信息(IIdentity)处理相同 TCP 连接上的后续请求。When this property is set to true and the first request over a particular TCP connection is authenticated using NTLM, subsequent requests over the same TCP connection are processed using the authentication information (IIdentity) of the initial request.

此属性在 NTLM 不是身份验证协议时无效。This property has no effect when NTLM is not the authentication protocol. 当 Negotiate 指定为身份验证协议时,只有当 NTLM 是用于身份验证的实际协议时,此属性才有效。When Negotiate is specified as the authentication protocol, this property has an effect only if NTLM is the actual protocol used for authentication.

备注

将此属性设置为 true 会提高性能,因为 HttpListener 不会发送其他 NTLM 身份验证质询,因此,不需要所有请求即可提供身份验证信息。While setting this property to true increases performance because the HttpListener does not send additional NTLM authentication challenges, there is a security risk in not requiring all requests to provide authentication information. 必须确定为提高性能冒此风险是否值得。You must determine whether the increase in performance is worth this risk.

适用于