CustomErrorsSection 类
配置 ASP.NET 自定义错误消息。
语法
class CustomErrorsSection : ConfigurationSectionWithCollection
方法
下表列出了 CustomErrorsSection
类公开的方法。
名称 | 说明 |
---|---|
添加 | (继承自 ConfigurationSectionWithCollection。) |
清除 | (从 ConfigurationSectionWithCollection 继承。) |
Get | (从 ConfigurationSectionWithCollection 继承。) |
GetAllowDefinition | (继承自 ConfigurationSection。) |
GetAllowLocation | (从 ConfigurationSection 继承。) |
删除 | (从 ConfigurationSectionWithCollection 继承。) |
RevertToParent | (从 ConfigurationSection 继承。) |
SetAllowDefinition | (从 ConfigurationSection 继承。) |
SetAllowLocation | (从 ConfigurationSection 继承。) |
属性
下表列出了 CustomErrorsSection
类公开的属性。
名称 | 描述 |
---|---|
CustomErrors |
指定 ASP.NET 自定义错误的 CustomError 值的数组。 |
DefaultRedirect |
必需的无空读/写 string 值,其中包含 HTTP 错误消息文件的默认路径或错误消息 URL。 此值由新创建的 CustomError 对象的 Redirect 属性继承。 |
Location |
(继承自 ConfigurationSection 。)一个键属性。 |
Mode |
一个读/写 sint32 枚举,指定是在本地还是远程显示自定义或默认错误页。 后文的“注解”部分列出了可能的值。 |
Path |
(继承自 ConfigurationSection 。)一个键属性。 |
SectionInformation |
(从 ConfigurationSection 继承。) |
子类
此类不包含子类。
注解
CustomErrorsSection
类表示的自定义错误特定于 ASP.NET,且位于 Web.config 文件的 <system.web>
部分。 每个错误都由 CustomError 类的实例表示。
HttpErrorsSection 类表示的自定义错误与 IIS 7 有关,且位于 ApplicationHost.config 文件的 <system.webServer>
部分。 每个错误都由 HttpErrorElement 类的实例表示。 在 IIS 7 中,ASP.NET 与 IIS 的集成使此名称发生更改成为必要。
下表列出了 Mode
属性的可能值。 默认值为 0 (RemoteOnly
)。
值 | 关键字 | 说明 |
---|---|---|
0 | RemoteOnly |
向本地用户显示默认 ASP.NET 错误页。 如果定义了自定义错误页,远程用户将收到一个自定义错误页。 如果没有为收到的错误定义任何自定义错误页,则会显示 IIS 错误页。 |
1 | On |
本地用户和远程用户都会显示用户定义的 ASP.NET 自定义错误页。 |
2 | Off |
本地用户和远程用户都会显示默认 ASP.NET 错误页。 |
示例
下面的示例将 DefaultRedirect
属性设置为“CustomError.htm”,并将 Mode
属性设置为 On
。
' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Get the custom errors section for the default Web site.
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")
oSite.GetSection "CustomErrorsSection", oSection
' Set the default redirect page to CustomError.htm,
' and set the Mode property to On.
oSection.DefaultRedirect = "CustomError.htm"
oSection.Mode = 1
oSection.Put_
继承层次结构
ConfigurationSectionWithCollection
CustomErrorsSection
要求
类型 | 描述 |
---|---|
客户端 | - IIS 7.0(在 Windows Vista 上) - IIS 7.5(在 Windows 7 上) - IIS 8.0(在 Windows 8 上) - IIS 10.0(在 Windows 10 上) |
服务器 | - IIS 7.0(在 Windows Server 2008 上) - IIS 7.5(在 Windows Server 2008 R2 上) - IIS 8.0(在 Windows Server 2012 上) - IIS 8.5(在 Windows Server 2012 R2 上) - IIS 10.0(在 Windows Server 2016 上) |
产品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 |
MOF 文件 | WebAdministration.mof |
另请参阅
ConfigurationSectionWithCollection 类
CustomError 类
HttpErrorElement 类
HttpErrorsSection 类