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