CustomErrorCollection.Add(CustomError) Metod

Definition

Lägger till ett CustomError objekt i samlingen.

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)

Parametrar

customError
CustomError

Objektet CustomError som ska läggas till finns redan i samlingen eller så är samlingen skrivskyddad.

Exempel

I följande kodexempel läggs ett CustomError objekt till i CustomErrorCollection samlingen.

Se kodexemplet i klassavsnittet CustomErrorCollection för att lära dig hur du hämtar samlingen.

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

Kommentarer

Innan du lägger till ett anpassat fel i samlingen måste du skapa ett CustomError felobjekt och initiera Redirect egenskaperna och StatusCode .

Gäller för