CustomErrorCollection.Add(CustomError) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
新增一個 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 一個錯誤物件並初始化 Redirect 和 StatusCode 屬性。