System.Net.HttpListenerContext Class
The HttpListenerContext
class provides access to request and response information used by the HttpListener
class to process HTTP requests.
Overview
Authors
Syntax
public sealed class HttpListenerContext
Inheritance
System.Object → System.Net.HttpListenerContext
Properties
Name | Type | Description |
---|---|---|
Request | HttpListenerRequest | Gets the request object that contains information about the client's request. |
Response | HttpListenerResponse | Gets the response object used to construct and send a response to the client. |
User | IPrincipal | Gets or sets the authenticated user for this request. |
Connection | HttpListenerConnection | Provides details about the underlying TCP connection. |
Methods
Name | Returns | Description |
---|---|---|
Abort() | void | Immediately aborts processing of the request and closes the connection. |
Close() | void | Finishes response processing and releases resources. |
Remarks
The HttpListenerContext
instance is created each time HttpListener.GetContext()
or HttpListener.BeginGetContext()
returns a new request. It encapsulates both the incoming request and the outgoing response, making it easier to handle them together.
Typical usage involves reading from Request.InputStream
and writing to Response.OutputStream
. Be sure to close or dispose the streams when finished to free the underlying network resources.