HttpParseException Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Undantaget som utlöses när ett parsfel inträffar.
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
- Arv
- Attribut
Exempel
I följande exempel visas hur du använder HttpParseException för att anpassa fel som genererats under sidparsing. I det här exemplet definieras en anpassad HtmlSelect kontroll. Om underordnade element i den anpassade kontrollen inte är av en angiven typ genereras en HttpParseException i den åsidosatta GetChildControlType metoden för en anpassad HtmlSelectBuilder. Om du vill generera ett parsningsfel ändrar du den underordnade elementliteralen MyCustomOption till en annan sträng.
<%@ 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
Kommentarer
Klassen HttpParseException är en HTTP-specifik undantagsklass som gör det möjligt för ASP.NET att skicka ut parser-undantagsinformation. Mer information om hur du genererar och hanterar undantag finns i Undantag.
Konstruktorer
| Name | Description |
|---|---|
| HttpParseException() |
Initierar en ny instans av HttpParseException klassen. |
| HttpParseException(String, Exception, String, String, Int32) |
Initierar en ny instans av HttpParseException klassen med specifik information om källkoden som kompileras och det radnummer som undantaget inträffade på. |
| HttpParseException(String, Exception) |
Initierar en ny instans av HttpParseException klassen med ett angivet felmeddelande och en referens till den inre. |
| HttpParseException(String) |
Initierar en ny instans av HttpParseException klassen med ett angivet felmeddelande. |
Egenskaper
| Name | Description |
|---|---|
| Data |
Hämtar en samling nyckel/värde-par som ger ytterligare användardefinierad information om undantaget. (Ärvd från Exception) |
| ErrorCode |
|
| FileName |
Hämtar namnet på filen som parsas när felet inträffar. |
| HelpLink |
Hämtar eller anger en länk till hjälpfilen som är associerad med det här undantaget. (Ärvd från Exception) |
| HResult |
Hämtar eller anger HRESULT, ett kodat numeriskt värde som har tilldelats ett specifikt undantag. (Ärvd från Exception) |
| InnerException |
Hämtar den Exception instans som orsakade det aktuella undantaget. (Ärvd från Exception) |
| Line |
Hämtar antalet rader som parsas när felet inträffar. |
| Message |
Hämtar ett meddelande som beskriver det aktuella undantaget. (Ärvd från Exception) |
| ParserErrors |
Hämtar parsningsfelen för det aktuella undantaget. |
| Source |
Hämtar eller anger namnet på programmet eller objektet som orsakar felet. (Ärvd från Exception) |
| StackTrace |
Hämtar en strängrepresentation av de omedelbara ramarna i anropsstacken. (Ärvd från Exception) |
| TargetSite |
Hämtar den metod som utlöser det aktuella undantaget. (Ärvd från Exception) |
| VirtualPath |
Hämtar den virtuella sökvägen till källfilen som genererade felet. |
| WebEventCode |
Hämtar de händelsekoder som är associerade med HTTP-undantaget. (Ärvd från HttpException) |
Metoder
| Name | Description |
|---|---|
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| GetBaseException() |
När den åsidosätts i en härledd klass returnerar den Exception som är rotorsaken till ett eller flera efterföljande undantag. (Ärvd från Exception) |
| GetHashCode() |
Fungerar som standard-hash-funktion. (Ärvd från Object) |
| GetHtmlErrorMessage() |
Hämtar HTML-felmeddelandet för att återgå till klienten. (Ärvd från HttpException) |
| GetHttpCode() |
Hämtar http-svarsstatuskoden för att återgå till klienten. (Ärvd från HttpException) |
| GetObjectData(SerializationInfo, StreamingContext) |
När det åsidosättas i en härledd klass anger du SerializationInfo objektet med information om undantaget. |
| GetType() |
Hämtar körningstypen för den aktuella instansen. (Ärvd från Exception) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som innehåller HRESULT för felet. (Ärvd från ExternalException) |
Händelser
| Name | Description |
|---|---|
| SerializeObjectState |
Föråldrad.
Inträffar när ett undantag serialiseras för att skapa ett undantagstillståndsobjekt som innehåller serialiserade data om undantaget. (Ärvd från Exception) |