This documentation is archived and is not being maintained.

CustomErrorCollection.Clear Method

Removes all CustomError objects from the collection.

Namespace:  System.Web.Configuration
Assembly:  System.Web (in System.Web.dll)

public void Clear()

The result of updating the configuration file after calling the Clear method is dependent upon the ConfigurationSaveMode chosen. To update the configuration file, you use one of these two overloads: Save and Save.

NoteNote:

Calling Save is equivalent to calling Save.

If you use the Save.method, the following conditions apply.

  • If you pass a Full or Modified parameter value, then a clear element is inserted into the clientTarget section of the configuration file at the current hierarchy level.

  • If you pass the Minimal parameter value, a series of remove elements are added to the clientTarget Element (ASP.NET Settings Schema) of the configuration file at the current hierarchy level. Each removes all references to an add element defined in a parent configuration file at a higher level in the hierarchy. When you use Minimal, there is one additional property on the collection that affects what gets serialized to the configuration file: EmitClear, which is false by default. The following conditions apply.

    • If the EmitClear set to true, clear element is inserted into the clientTarget 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.

    • If the EmitClear flag is set to false, the clear element is removed from the clientTarget section of the configuration file at the current hierarchy level, if it exists.

The Clear method actually deletes the add elements defined in the clientTarget 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.

NoteNote:

The add elements are not deleted from the clientTarget section of the parent configuration files.

The following code example removes all the CustomError objects from the CustomErrorCollection collection. Refer to the code example in the CustomErrorCollection class topic to learn how to get the collection.

// Using the Clear method. 
if (!customErrorsSection.SectionInformation.IsLocked)
{
    // Execute the Clear method.
    customErrorsCollection.Clear();
    configuration.Save();
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: