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

适用于