HttpParseException 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
发生分析错误时引发的异常。
public ref class HttpParseException sealed : System::Web::HttpExceptionpublic sealed class HttpParseException : System.Web.HttpException[System.Serializable]
public sealed class HttpParseException : System.Web.HttpExceptiontype HttpParseException = class
    inherit HttpException[<System.Serializable>]
type HttpParseException = class
    inherit HttpExceptionPublic NotInheritable Class HttpParseException
Inherits HttpException- 继承
- 属性
示例
以下示例演示如何使用自定义 HttpParseException 在页面分析期间生成的错误。 在此示例中,定义了自定义 HtmlSelect 控件。 如果自定义控件的子元素不是指定类型,则会在自定义的重写GetChildControlType方法中引发一HtmlSelectBuilder个HttpParseException元素。 若要生成分析异常,请将子元素文本 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) | 用指定的错误消息初始化 HttpParseException 类的新实例。 | 
| HttpParseException(String, Exception) | 使用指定的错误消息和对内部异常的引用来初始化 HttpParseException 类的新实例。 | 
| HttpParseException(String, Exception, String, String, Int32) | 使用关于正在编译的源代码的特定信息和发生异常的行号初始化 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 对象。 | 
| GetObjectData(SerializationInfo, StreamingContext) | 获取关于异常的信息并将其添加到 SerializationInfo 对象。(继承自 HttpException) | 
| GetType() | 获取当前实例的运行时类型。(继承自 Exception) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回一个字符串,该字符串包含错误的 HRESULT。(继承自 ExternalException) | 
事件
| SerializeObjectState | 
		已过时。 
	 当异常被序列化用来创建包含有关该异常的徐列出数据的异常状态对象时会出现该问题。(继承自 Exception) |