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 属性。

适用于