HttpListenerPrefixCollection.Remove Method

Removes the specified Uniform Resource Identifier (URI) from the list of prefixes handled by the HttpListener object.

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

public bool Remove (
	string uriPrefix
public final boolean Remove (
	String uriPrefix
public final function Remove (
	uriPrefix : String
) : boolean
Not applicable.



A String that contains the URI prefix to remove.

Return Value

true if the uriPrefix was found in the HttpListenerPrefixCollection and removed; otherwise false.

Exception typeCondition


uriPrefix is a null reference (Nothing in Visual Basic).


A Windows function call failed. To determine the cause of the exception, check the exception's error code.


The HttpListener associated with this collection is closed.

If uriPrefix is not in the collection, this method does nothing.

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 removes a user-specified prefix from a HttpListenerPrefixCollection.

public static boolean RemovePrefix(HttpListener listener, String prefix)
    // Get the prefixes that the Web server is listening to.
    HttpListenerPrefixCollection prefixes = listener.get_Prefixes();
    if (prefixes.get_Count() == 0 || prefix == null || prefix.get_Length() 
        == 0) {
        return false;
    try {
    // If the operation failed, return false.
    catch (System.Exception exp) {
        return false;
    return true;
} //RemovePrefix

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 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

Community Additions