UrlMappingCollection.Clear Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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 theurlMappings
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 theurlMappings
of the configuration file at the current hierarchy level. Theseremove
elements remove all references to theadd
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 isfalse
by default. One of the following conditions applies:EmitClear set to
true
. Aclear
element is inserted into theurlMappings
section of the configuration file at the current hierarchy level. This removes all references to theadd
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 theclear
element from theurlMappings
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.