HttpListener.IgnoreWriteExceptions 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 Boolean 值,指定您的應用程式是否要接收在 HttpListener 傳送回應至用戶端時所發生的例外狀況。
public:
property bool IgnoreWriteExceptions { bool get(); void set(bool value); };
public bool IgnoreWriteExceptions { get; set; }
member this.IgnoreWriteExceptions : bool with get, set
Public Property IgnoreWriteExceptions As Boolean
屬性值
true
如果這 HttpListener 不應該傳回將回應傳送至用戶端時所發生的例外狀況,則為 , 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
設定為 。