Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HttpListener.Prefixes Property

Gets the Uniform Resource Identifier (URI) prefixes handled by this HttpListener object.

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

public HttpListenerPrefixCollection Prefixes { get; }
/** @property */
public HttpListenerPrefixCollection get_Prefixes ()

public function get Prefixes () : HttpListenerPrefixCollection

Not applicable.

Property Value

An HttpListenerPrefixCollection that contains the URI prefixes that this HttpListener object is configured to handle.

Exception typeCondition

ObjectDisposedException

This object has been closed.

The prefixes are in canonical form. For a detailed description of prefixes, see the HttpListener class overview.

The following code example demonstrates using the Prefixes property to obtain and print the URI prefixes that are handled.

public static void DisplayPrefixesAndState(HttpListener listener)
{
    // List the prefixes to which the server listens.
    HttpListenerPrefixCollection prefixes = listener.Prefixes;
    if (prefixes.Count == 0)
    {
        Console.WriteLine("There are no prefixes.");
    }
    foreach(string prefix in prefixes)
    {
        Console.WriteLine(prefix);
    }
    // Show the listening state.
    if (listener.IsListening)
    {
        Console.WriteLine("The server is listening.");
    }
}

public static void DisplayPrefixesAndState(HttpListener listener)
{
    // List the prefixes to which the server listens.
    HttpListenerPrefixCollection prefixes = listener.get_Prefixes();
    if (prefixes.get_Count() == 0) {
        Console.WriteLine("There are no prefixes.");
    }

    IEnumerator objEnum = prefixes.GetEnumerator();
    String prefix;
    while (objEnum.MoveNext()) {
        prefix = objEnum.get_Current().ToString();
        Console.WriteLine(prefix);
    }
    // Show the listening state.
    if (listener.get_IsListening()) {
        Console.WriteLine("The server is listening.");
    }
} //DisplayPrefixesAndState

Windows 98, Windows Server 2003, Windows XP Media Center Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft