HttpListenerPrefixCollection.Clear 方法

定义

从该集合中移除所有的统一资源标识符 (URI) 前缀。

public:
 virtual void Clear();
public void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()

实现

例外

Windows 函数调用失败。 检查异常的 ErrorCode 属性以确定导致异常的原因。

已关闭与此集合关联的 HttpListener

示例

下面的代码示例删除 中的所有 HttpListenerPrefixCollection前缀。

public static bool RemoveAllPrefixes(HttpListener listener)
{
    // Get the prefixes that the Web server is listening to.
    HttpListenerPrefixCollection prefixes = listener.Prefixes;
    try
    {
        prefixes.Clear();
    }
    // If the operation failed, return false.
    catch
    {
        return false;
    }
    return true;
}
Public Shared Function RemoveAllPrefixes(ByVal listener As HttpListener) As Boolean
    ' Get the prefixes that the Web server is listening to.
    Dim prefixes As HttpListenerPrefixCollection = listener.Prefixes

    Try
        prefixes.Clear()
    Catch ' If the operation failed, return false.
        Return False
    End Try

    Return True
End Function

注解

调用此方法后,无法在不添加新前缀的情况下启动关联的 HttpListener ;如果尝试这样做,将引发异常。

调用方说明

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。 有关详细信息,请参阅.NET Framework中的网络跟踪

适用于

另请参阅