CustomErrorCollection.Add(CustomError) Metoda

Definicja

CustomError Dodaje obiekt do kolekcji.

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)

Parametry

customError
CustomError

CustomError Obiekt do dodania już istnieje w kolekcji lub kolekcja jest tylko do odczytu.

Przykłady

Poniższy przykład kodu dodaje CustomError obiekt do kolekcji CustomErrorCollection .

Zapoznaj się z przykładem kodu w temacie klasy, CustomErrorCollection aby dowiedzieć się, jak pobrać kolekcję.

// 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

Uwagi

Przed dodaniem błędu niestandardowego do kolekcji należy utworzyć obiekt błędu i zainicjować CustomErrorRedirect właściwości i StatusCode .

Dotyczy