HttpException 클래스

정의

HTTP 요청을 처리하는 동안 발생한 예외를 설명합니다.

public ref class HttpException : System::Runtime::InteropServices::ExternalException
public class HttpException : System.Runtime.InteropServices.ExternalException
[System.Serializable]
public class HttpException : System.Runtime.InteropServices.ExternalException
type HttpException = class
    inherit ExternalException
[<System.Serializable>]
type HttpException = class
    inherit ExternalException
Public Class HttpException
Inherits ExternalException
상속
파생
특성

예제

다음 코드 예제에서는 클래스를 사용 하 여 HttpException 사용자 지정 된 예외를 발생 하는 방법을 보여 줍니다. 이 메서드는 Button_Click 클릭한 단추를 확인한 다음 해당 단추 또는 CheckBoolean 메서드를 CheckNumber 호출합니다. 입력란의 사용자가 입력한 값이 예상된 형식과 일치하지 않으면 오류 유형 HttpException 에 따라 사용자 지정된 메시지와 함께 예외가 만들어지고 throw됩니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    void CheckNumber()
    {
        try
        {
            // Check whether the value is an integer.
            String convertInt = textbox1.Text;
            Convert.ToInt32(convertInt);
        }
        catch (Exception e)
        {
            // Throw an HttpException with customized message.
            throw new HttpException("not an integer");
        }
    }
    void CheckBoolean()
    {
        try
        {
            // Check whether the value is an boolean.
            String convertBool = textbox1.Text;
            Convert.ToBoolean(convertBool);
        }
        catch (Exception e)
        {
            // Throw an HttpException with customized message.
            throw new HttpException("not a boolean");
        }
    }

    void Button_Click(Object sender, EventArgs e)
    {
        try
        {
            // Check to see which button was clicked.
            Button b = (Button)sender;
            if (b.ID.StartsWith("button1"))
                CheckNumber();
            else if (b.ID.StartsWith("button2"))
                CheckBoolean();

            label1.Text = "You entered: " + textbox1.Text;
            label1.ForeColor = System.Drawing.Color.Black;
        }
        // Catch the HttpException.
        catch (HttpException exp)
        {
            label1.Text = "An HttpException was raised. "
               + "The value entered in the textbox is " + exp.Message.ToString();
            label1.ForeColor = System.Drawing.Color.Red;
        }
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HttpException Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        <b>Enter a value in the text box.</b>
        <br />
        <asp:TextBox ID="textbox1" 
                     Runat="server">
        </asp:TextBox>
        <br />
        <asp:Button ID="button1"
                    Text="Check for integer."  
                    OnClick="Button_Click" 
                    Runat="server">
        </asp:Button>
        <br />
        <asp:Button ID="button2"
                    Text="Check for boolean." 
                    OnClick="Button_Click" 
                    Runat="server">
        </asp:Button>
        <br />
        <asp:Label ID="label1" 
                   Runat="server">
        </asp:Label>    
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  Sub CheckNumber()
    
    Try

      ' Check whether the value is an integer.
      Dim convertInt As String = textbox1.Text
      Convert.ToInt32(convertInt)

    Catch e As Exception

      ' Throw an HttpException with customized message.
      Throw New HttpException("not an integer")

    End Try

  End Sub

  Sub CheckBoolean()
    
    Try

      ' Check whether the value is an boolean.
      Dim convertBool As String = textbox1.Text
      Convert.ToBoolean(convertBool)

    Catch e As Exception

      ' Throw an HttpException with customized message.
      Throw New HttpException("not a boolean")

    End Try

  End Sub

  Sub Button_Click(ByVal sender As [Object], ByVal e As EventArgs)
    
    Try

      ' Check to see which button was clicked.
      Dim b As Button = CType(sender, Button)
      If b.ID.StartsWith("button1") Then
        CheckNumber()
      ElseIf b.ID.StartsWith("button2") Then
        CheckBoolean()
      End If

      label1.Text = "You entered: " + textbox1.Text
      label1.ForeColor = System.Drawing.Color.Black

      ' Catch the HttpException.
    Catch exp As HttpException

      label1.Text = "An HttpException was raised. " + "The value entered in the textbox is " + exp.Message.ToString()
      label1.ForeColor = System.Drawing.Color.Red

    End Try

  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HttpException Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        <b>Enter a value in the text box.</b>
        <br />
        <asp:TextBox ID="textbox1" 
                     Runat="server">
        </asp:TextBox>
        <br />
        <asp:Button ID="button1"
                    Text="Check for integer."  
                    OnClick="Button_Click" 
                    Runat="server">
        </asp:Button>
        <br />
        <asp:Button ID="button2"
                    Text="Check for boolean." 
                    OnClick="Button_Click" 
                    Runat="server">
        </asp:Button>
        <br />
        <asp:Label ID="label1" 
                   Runat="server">
        </asp:Label>    
    </div>
    </form>
</body>
</html>

설명

클래스는 HttpException ASP.NET 예외 정보를 생성할 수 있도록 하는 HTTP 관련 예외 클래스입니다. 예외 throw 및 처리에 대한 자세한 내용은 예외를 참조 하세요.

생성자

HttpException()

HttpException 클래스의 새 인스턴스를 초기화하여 빈 HttpException 개체를 만듭니다.

HttpException(Int32, String)

HTTP 응답 상태 코드 및 오류 메시지를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

HttpException(Int32, String, Exception)

HTTP 응답 상태 코드, 오류 메시지 및 HttpException 속성을 사용하여 InnerException 클래스의 새 인스턴스를 초기화합니다.

HttpException(Int32, String, Int32)

HTTP 응답 상태 코드, 오류 메시지 및 예외 코드를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

HttpException(SerializationInfo, StreamingContext)

serialize된 데이터를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

HttpException(String)

제공된 오류 메시지를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

HttpException(String, Exception)

오류 메시지와 HttpException 속성을 사용하여 InnerException 클래스의 새 인스턴스를 초기화합니다.

HttpException(String, Int32)

오류 메시지와 예외 코드를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

속성

Data

예외에 대한 사용자 정의 정보를 추가로 제공하는 키/값 쌍 컬렉션을 가져옵니다.

(다음에서 상속됨 Exception)
ErrorCode

오류의 HRESULT를 가져옵니다.

(다음에서 상속됨 ExternalException)
HelpLink

이 예외와 연결된 도움말 파일에 대한 링크를 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
HResult

특정 예외에 할당된 코드화된 숫자 값인 HRESULT를 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
InnerException

현재 예외를 발생시킨 Exception 인스턴스를 가져옵니다.

(다음에서 상속됨 Exception)
Message

현재 예외를 설명하는 메시지를 가져옵니다.

(다음에서 상속됨 Exception)
Source

오류를 발생시키는 애플리케이션 또는 개체의 이름을 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
StackTrace

호출 스택의 직접 실행 프레임 문자열 표현을 가져옵니다.

(다음에서 상속됨 Exception)
TargetSite

현재 예외를 throw하는 메서드를 가져옵니다.

(다음에서 상속됨 Exception)
WebEventCode

HTTP 예외와 연결된 이벤트 코드를 가져옵니다.

메서드

CreateFromLastError(String)

Windows API GetLastError() 메서드에서 반환되는 오류 코드를 기반으로 하는 새 HttpException 예외를 만듭니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetBaseException()

파생 클래스에서 재정의된 경우 하나 이상의 후속 예외의 근본 원인이 되는 Exception 을 반환합니다.

(다음에서 상속됨 Exception)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetHtmlErrorMessage()

HTML 오류 메시지를 가져와 클라이언트에게 반환합니다.

GetHttpCode()

HTTP 상태 응답 코드를 가져와 클라이언트에게 반환합니다.

GetObjectData(SerializationInfo, StreamingContext)

예외에 대한 정보를 가져와 SerializationInfo 개체에 추가합니다.

GetObjectData(SerializationInfo, StreamingContext)

파생 클래스에서 재정의된 경우 예외에 관한 정보를 SerializationInfo 에 설정합니다.

(다음에서 상속됨 Exception)
GetType()

현재 인스턴스의 런타임 형식을 가져옵니다.

(다음에서 상속됨 Exception)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

오류의 HRESULT가 들어 있는 문자열을 반환합니다.

(다음에서 상속됨 ExternalException)

이벤트

SerializeObjectState
사용되지 않습니다.

예외에 대한 serialize된 데이터가 들어 있는 예외 상태 개체가 만들어지도록 예외가 serialize될 때 발생합니다.

(다음에서 상속됨 Exception)

적용 대상

추가 정보