HttpParseException 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
发生分析错误时引发的异常。
public ref class HttpParseException sealed : System::Web::HttpException
public sealed class HttpParseException : System.Web.HttpException
[System.Serializable]
public sealed class HttpParseException : System.Web.HttpException
type HttpParseException = class
inherit HttpException
[<System.Serializable>]
type HttpParseException = class
inherit HttpException
Public NotInheritable Class HttpParseException
Inherits HttpException
- 继承
- 属性
示例
以下示例演示如何使用 HttpParseException 自定义在页面分析过程中生成的错误。 在此示例中,定义了自定义 HtmlSelect 控件。 如果自定义控件的子元素不是指定类型,则会在自定义的重写HttpParseException方法中引发一GetChildControlType个HtmlSelectBuilder。 若要生成分析异常,请将子元素文本 MyCustomOption 更改为任何其他字符串。
<%@ Page Language="C#"%>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HttpParseException Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>HttpParseException Example</h3>
<aspSample:CustomHtmlSelectWithHttpParseException
id="customhtmlselect1"
runat="server">
<aspSample:MyCustomOption optionid="option1" value="1"/>
<aspSample:MyCustomOption optionid="option2" value="2"/>
<aspSample:MyCustomOption optionid="option3" value="3"/>
</aspSample:CustomHtmlSelectWithHttpParseException>
</form>
</body>
</html>
<%@ Page Language="VB"%>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HttpParseException Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>HttpParseException Example</h3>
<aspSample:CustomHtmlSelectWithHttpParseException
id="customhtmlselect1"
runat="server">
<aspSample:MyCustomOption optionid="option1" value="1"/>
<aspSample:MyCustomOption optionid="option2" value="2"/>
<aspSample:MyCustomOption optionid="option3" value="3"/>
</aspSample:CustomHtmlSelectWithHttpParseException>
</form>
</body>
</html>
using System;
using System.Security.Permissions;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Samples.AspNet.CS
{
// Define a child control for the custom HtmlSelect.
public class MyCustomOption
{
string _id;
string _value;
public string optionid
{
get
{ return _id; }
set
{ _id = value; }
}
public string value
{
get
{ return _value; }
set
{ _value = value; }
}
}
// Define a custom HtmlSelectBuilder.
public class MyHtmlSelectBuilderWithparseException : HtmlSelectBuilder
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public override Type GetChildControlType(string tagName, IDictionary attribs)
{
// Distinguish between two possible types of child controls.
if (tagName.ToLower().EndsWith("mycustomoption"))
{
return typeof(MyCustomOption);
}
else
{
throw new HttpParseException("This custom HtmlSelect control" + "requires child elements of the form \"MyCustomOption\"");
}
}
}
[ControlBuilderAttribute(typeof(MyHtmlSelectBuilderWithparseException))]
public class CustomHtmlSelectWithHttpParseException : HtmlSelect
{
// Override the AddParsedSubObject method.
protected override void AddParsedSubObject(object obj)
{
string _outputtext;
if (obj is MyCustomOption)
{
_outputtext = "custom select option : " + ((MyCustomOption)obj).value;
ListItem li = new ListItem(_outputtext, ((MyCustomOption)obj).value);
base.Items.Add(li);
}
}
}
}
Imports System.Security.Permissions
Imports System.Collections
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Namespace Samples.AspNet.VB
' Define a child control for the custom HtmlSelect.
Public Class MyCustomOption
Private _id As String
Private _value As String
Public Property optionid() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
Public Property value() As String
Get
Return _value
End Get
Set(ByVal value As String)
_value = value
End Set
End Property
End Class
' Define a custom HtmlSelectBuilder.
Public Class MyHtmlSelectBuilderWithparseException
Inherits HtmlSelectBuilder
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Overrides Function GetChildControlType(ByVal tagName As String, ByVal attribs As IDictionary) As Type
' Distinguish between two possible types of child controls.
If tagName.ToLower().EndsWith("mycustomoption") Then
Return GetType(MyCustomOption)
Else
Throw New HttpParseException("This custom HtmlSelect control" & _
"requires child elements of the form ""MyCustomOption""")
End If
End Function
End Class
<ControlBuilderAttribute(GetType(MyHtmlSelectBuilderWithparseException))> _
Public Class CustomHtmlSelectWithHttpParseException
Inherits HtmlSelect
' Override the AddParsedSubObject method.
Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)
Dim _outputtext As String
If TypeOf obj Is MyCustomOption Then
_outputtext = "custom select option : " + CType(obj, MyCustomOption).value
Dim li As New ListItem(_outputtext, CType(obj, MyCustomOption).value)
MyBase.Items.Add(li)
End If
End Sub
End Class
End Namespace
注解
HttpParseException 类是一个特定于 HTTP 的异常类,它使 ASP.NET 能够输出分析程序异常信息。 有关引发和处理异常的详细信息,请参阅 异常。
构造函数
| 名称 | 说明 |
|---|---|
| HttpParseException() |
初始化 HttpParseException 类的新实例。 |
| HttpParseException(String, Exception, String, String, Int32) |
使用有关要编译的 HttpParseException 源代码以及发生异常的行号的特定信息初始化类的新实例。 |
| HttpParseException(String, Exception) |
使用指定的错误消息和对内部的引用初始化类的新实例 HttpParseException 。 |
| HttpParseException(String) |
使用指定的错误消息初始化类的新实例 HttpParseException 。 |
属性
| 名称 | 说明 |
|---|---|
| Data |
获取键/值对的集合,这些键/值对提供有关异常的其他用户定义的信息。 (继承自 Exception) |
| ErrorCode |
获取错误的 |
| FileName |
获取发生错误时要分析的文件的名称。 |
| HelpLink |
获取或设置与此异常关联的帮助文件的链接。 (继承自 Exception) |
| HResult |
获取或设置 HRESULT,它是分配给特定异常的编码数值。 (继承自 Exception) |
| InnerException |
Exception获取导致当前异常的实例。 (继承自 Exception) |
| Line |
获取发生错误时要分析的行数。 |
| Message |
获取描述当前异常的消息。 (继承自 Exception) |
| ParserErrors |
获取当前异常分析器错误。 |
| Source |
获取或设置导致错误的应用程序或对象的名称。 (继承自 Exception) |
| StackTrace |
获取调用堆栈上即时帧的字符串表示形式。 (继承自 Exception) |
| TargetSite |
获取引发当前异常的方法。 (继承自 Exception) |
| VirtualPath |
获取生成错误的源文件的虚拟路径。 |
| WebEventCode |
获取与 HTTP 异常关联的事件代码。 (继承自 HttpException) |
方法
| 名称 | 说明 |
|---|---|
| Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
| GetBaseException() |
在派生类中重写时,返回 Exception 一个或多个后续异常的根本原因。 (继承自 Exception) |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetHtmlErrorMessage() |
获取要返回到客户端的 HTML 错误消息。 (继承自 HttpException) |
| GetHttpCode() |
获取要返回到客户端的 HTTP 响应状态代码。 (继承自 HttpException) |
| GetObjectData(SerializationInfo, StreamingContext) |
在派生类中重写时,使用有关异常的信息设置 SerializationInfo 对象。 |
| GetType() |
获取当前实例的运行时类型。 (继承自 Exception) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回包含错误的 HRESULT 的字符串。 (继承自 ExternalException) |
活动
| 名称 | 说明 |
|---|---|
| SerializeObjectState |
已过时.
序列化异常以创建包含有关异常的序列化数据的异常状态对象时发生。 (继承自 Exception) |