Export (0) Print
Expand All

HttpListener::GetContext Method

Waits for an incoming request and returns when one is received.

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

public:
HttpListenerContext^ GetContext()

Return Value

Type: System.Net::HttpListenerContext
An HttpListenerContext object that represents a client request.

ExceptionCondition
HttpListenerException

A Win32 function call failed. Check the exception's ErrorCode property to determine the cause of the exception.

InvalidOperationException

This object has not been started or is currently stopped.

-or-

The HttpListener does not have any Uniform Resource Identifier (URI) prefixes to respond to. See Remarks.

ObjectDisposedException

This object is closed.

Before calling this method, you must call the Start method and add at least one URI prefix to listen for by adding the URI strings to the HttpListenerPrefixCollection returned by the Prefixes property. For a detailed description of prefixes, see the HttpListener class overview.

This method blocks while waiting for an incoming request. If you want incoming requests to be processed asynchronously (on separate threads) so that your application does not block, use the BeginGetContext method.

Notes to Callers

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing.

The following code example demonstrates calling this method.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft