Share via


CustomErrorCollection.Add(CustomError) Metodo

Definizione

Aggiunge un oggetto CustomError alla raccolta.

public:
 void Add(System::Web::Configuration::CustomError ^ customError);
public void Add (System.Web.Configuration.CustomError customError);
member this.Add : System.Web.Configuration.CustomError -> unit
Public Sub Add (customError As CustomError)

Parametri

customError
CustomError

L'oggetto CustomError da aggiungere è già presente nell'insieme oppure l'insieme è di sola lettura.

Esempio

Nell'esempio di codice seguente viene aggiunto un CustomError oggetto all'insieme CustomErrorCollection .

Per informazioni su come ottenere la raccolta, vedere l'esempio di codice nell'argomento CustomErrorCollection della classe.

// Using the Add method.
CustomError newCustomError2 =
new CustomError(404, "customerror404.htm");

// Update the configuration file.
if (!customErrorsSection.SectionInformation.IsLocked)
{
    // Add the new custom error to the collection.
    customErrorsCollection.Add(newCustomError2);
    configuration.Save();
}
' Using the Add method.
  Dim newCustomError2 _
  As New CustomError(404, "customerror404.htm")

' Update the configuration file.
If Not customErrorsSection.SectionInformation.IsLocked Then
   ' Add the new custom error to the collection.
   customErrorsCollection.Add(newCustomError2)
   configuration.Save()
End If

Commenti

Prima di aggiungere un errore personalizzato alla raccolta, è necessario creare un CustomError oggetto error e inizializzare le Redirect proprietà e StatusCode .

Si applica a