HttpListener.IgnoreWriteExceptions Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a Boolean value that specifies whether your application receives exceptions that occur when an HttpListener sends the response to the client.
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
if this HttpListener should not return exceptions that occur when sending the response to the client; otherwise, false
. The 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
Set this property to true
if your application does not require that a response is successfully sent to each client.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: