UrlMappingCollection.Clear 方法

定义

从集合中移除所有 UrlMapping 对象。Removes all the UrlMapping objects from the collection.

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

示例

下面的代码示例 UrlMapping 从中移除所有对象 UrlMappingCollectionThe following code example removes all UrlMapping objects from the UrlMappingCollection.

有关如何获取集合的详细说明,请参阅类主题中的代码示例 UrlMappingCollectionRefer to the code example in the UrlMappingCollection class topic to learn how to get the collection.


// Clear the url mapping collection.
urlMappings.Clear();

// Update the configuration file.

// Define the save modality.
ConfigurationSaveMode saveMode =
  ConfigurationSaveMode.Minimal;

urlMappings.EmitClear =
   Convert.ToBoolean(parm2);

if (parm1 == "none")
{
  if (!urlMappingSection.IsReadOnly())
    configuration.Save();
  msg = String.Format(
  "Default modality, EmitClear:      {0}",
  urlMappings.EmitClear.ToString());
}
else
{
  if (parm1 == "full")
    saveMode = ConfigurationSaveMode.Full;
  else
    if (parm1 == "modified")
      saveMode = ConfigurationSaveMode.Modified;

  if (!urlMappingSection.IsReadOnly())
    configuration.Save(saveMode);

  msg = String.Format(
   "Save modality:      {0}",
   saveMode.ToString());
}

' Clear the url mapping collection.
urlMappings.Clear()

' Update the configuration file.
' Define the save modality.
Dim saveMode _
As ConfigurationSaveMode = _
ConfigurationSaveMode.Minimal

urlMappings.EmitClear = _
Convert.ToBoolean(parm2)

If parm1 = "none" Then
    If Not urlMappingSection.IsReadOnly() Then
        configuration.Save()
    End If
    msg = String.Format( _
    "Default modality, EmitClear:      {0}", _
    urlMappings.EmitClear.ToString())
Else
    If parm1 = "full" Then
        saveMode = ConfigurationSaveMode.Full
    ElseIf parm1 = "modified" Then
        saveMode = ConfigurationSaveMode.Modified
    End If
    If Not urlMappingSection.IsReadOnly() Then
        configuration.Save(saveMode)
    End If
    msg = String.Format( _
    "Save modality:      {0}", _
    saveMode.ToString())
End If

注解

如果在调用方法后保存配置文件 Clear ,结果将取决于所选的 ConfigurationSaveModeIf you save the configuration file after calling the Clear method, the result will be dependent upon the chosen ConfigurationSaveMode.

以下列表描述了使用方法保存文件时适用的条件 SaveThe following list describes the conditions that apply if you use the Save method to save the file:

  • 如果将 FullConfigurationSaveMode.Modified 作为参数值传递,则 clearurlMappings 在当前层次结构级别的配置文件的部分中插入元素。If you pass Full or ConfigurationSaveMode.Modified as the parameter value, a clear element is inserted into the urlMappings section of the configuration file at the current hierarchy level.

  • 如果 Minimal 作为参数值传递,则会将一系列 remove 元素添加到 urlMappings 当前层次结构级别的配置文件的中。If you pass Minimal as the parameter value, a series of remove elements are added to the urlMappings of the configuration file at the current hierarchy level. 这些 remove 元素删除对 add 层次结构中较高级别上的父配置文件中定义的元素的所有引用。These remove elements remove all references to the add elements defined in the parent configuration files at higher levels in the hierarchy. 对于 Minimal 枚举值,集合上还有一个附加属性,该属性会影响序列化到配置文件的内容。With the Minimal enumeration value, there is one additional property on the collection that affects what gets serialized to the configuration file. 属性为 EmitClear ,并且 false 默认为。The property is EmitClear and is false by default. 以下条件之一适用:One of the following conditions applies:

    • EmitClear 设置为 trueEmitClear set to true. clear元素插入到 urlMappings 配置文件中当前层次结构级别的部分。A clear element is inserted into the urlMappings section of the configuration file at the current hierarchy level. 这将删除对 add 层次结构中较高级别上的父配置文件中定义的元素的所有引用。This removes all references to the add elements defined in the parent configuration files at higher levels in the hierarchy.

    • EmitClear 标志设置为 falseEmitClear flag is set to false. 这具有 clearurlMappings 当前层次结构级别的配置文件的部分中删除元素(如果存在)的效果。This has the effect of removing the clear element from the urlMappings section of the configuration file at the current hierarchy level, if it exists.

Clear方法实际删除 addurlMappings 当前层次结构级别的配置文件的部分中定义的元素。The Clear method actually deletes the add elements defined in the urlMappings section of the configuration file at the current hierarchy level. 它还删除对 add 层次结构中较高级别上的父配置文件中定义的元素的所有引用,但不会删除它们。It also removes all references to the add elements defined in the parent configuration files at higher levels in the hierarchy but does not delete them.

适用于

另请参阅