共用方式為


HttpListener.UnsafeConnectionNtlmAuthentication 屬性

定義

取得或設定 Boolean 值,控制使用 NTLM 時,是否必須驗證其他使用相同傳輸控制通訊協定 (TCP) 連接的要求。

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;否則為 false。 預設值是 false

例外狀況

此物件已關閉。

範例

下列程式代碼範例示範如何設定此屬性。

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 連線的後續要求。

當 NTLM 不是驗證通訊協定時,這個屬性不會有任何作用。 當 Negotiate 指定為驗證通訊協定時,只有當 NTLM 是用於驗證的實際通訊協定時,這個屬性才會生效。

注意

雖然將此屬性設定為 true 提高效能,因為 HttpListener 不會傳送額外的NTLM驗證挑戰,但不需要所有要求提供驗證資訊的安全性風險。 您必須決定是否值得冒這個風險以提升效能。

適用於