HttpListener.Prefixes Property

Definition

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

public System.Net.HttpListenerPrefixCollection Prefixes { get; }

Property Value

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

Exceptions

This object has been closed.

Examples

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.");
    }
}

Remarks

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

Applies to

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