HttpListenerContext Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Provides access to the request and response objects used by the HttpListener class. This class cannot be inherited.

System..::..Object
  System.Net..::..HttpListenerContext

Namespace:  System.Net
Assembly:  System.Http (in System.Http.dll)

public class HttpListenerContext

The HttpListenerContext type exposes the following members.

  NameDescription
Public propertyRequestGets the HttpListenerRequest that represents a client's request for a resource.
Public propertyResponseGets the HttpListenerResponse object that will be sent to the client in response to the client's request.
Top

  NameDescription
Public methodClose()()()()Closes the stream attached to this listener context.
Public methodClose(Int32)Closes the stream attached to this listener context with the specified value for how long the socket should linger after closing.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodResetClears values for the HttpListenerContext instance.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

This class provides the information related to a client's Hypertext Transfer Protocol (HTTP) request being processed by an HttpListener object. This class also has methods that allow an HttpListener object to accept a WebSocket connection.

The GetContext method returns instances of the HttpListenerContext class. To get the object that represents the client request, use the Request property. To get the object that represents the response that will be sent to the client by the HttpListener, use the Response property. To get user information about the client sending the request, such as its login name and whether it has been authenticated, you can query the properties in the IPrincipal object returned by the User property.

Closing an HttpListenerContext object sends the response to the client and frees any resources used by the HttpListenerContext. Aborting an HttpListenerContext object discards the response to the client if it has not already been sent, and frees any resources used by the HttpListenerContext. After closing or aborting an HttpListenerContext object, you cannot reference its methods or properties. If you do so, you will receive an ObjectDisposedException exception.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: