Bewerken

Delen via


UrlMappingCollection.Clear Method

Definition

Removes all the UrlMapping objects from the collection.

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

Examples

The following code example removes all UrlMapping objects from the UrlMappingCollection.

Refer 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

Remarks

If you save the configuration file after calling the Clear method, the result will be dependent upon the chosen ConfigurationSaveMode.

The following list describes the conditions that apply if you use the Save method to save the file:

  • 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.

  • 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. These remove elements remove all references to the add elements defined in the parent configuration files at higher levels in the hierarchy. With the Minimal enumeration value, there is one additional property on the collection that affects what gets serialized to the configuration file. The property is EmitClear and is false by default. One of the following conditions applies:

    • EmitClear set to true. A clear element is inserted into the urlMappings section of the configuration file at the current hierarchy level. This removes all references to the add elements defined in the parent configuration files at higher levels in the hierarchy.

    • EmitClear flag is set to false. 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.

The Clear method actually deletes the add elements defined in the urlMappings section of the configuration file at the current hierarchy level. 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.

Applies to

See also