Share via


CustomErrorCollection.Add(CustomError) 方法

定義

CustomError 物件加入至集合。

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)

參數

customError
CustomError

要加入的 CustomError 物件已經存在於集合中,或者集合是唯讀的。

範例

下列程式碼範例會將 CustomError 物件新增至 CustomErrorCollection 集合。

請參閱類別主題中的 CustomErrorCollection 程式碼範例,以瞭解如何取得集合。

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

備註

在將自訂錯誤新增至集合之前,您必須建立 CustomError 錯誤物件並初始化 RedirectStatusCode 屬性。

適用於