Page.Context 속성

정의

페이지와 관련된 HttpContext 개체를 가져옵니다.

protected:
 virtual property System::Web::HttpContext ^ Context { System::Web::HttpContext ^ get(); };
protected public:
 virtual property System::Web::HttpContext ^ Context { System::Web::HttpContext ^ get(); };
protected override System.Web.HttpContext Context { get; }
protected internal override System.Web.HttpContext Context { get; }
member this.Context : System.Web.HttpContext
Protected Overrides ReadOnly Property Context As HttpContext
Protected Friend Overrides ReadOnly Property Context As HttpContext

속성 값

HttpContext

현재 페이지와 관련된 정보를 포함하는 HttpContext 개체입니다.

예제

다음 코드 예제에서는 속성을 사용 하 여 Context 및 메서드 및 HttpContext.ClearError 속성에 액세스 HttpContext.AddError 합니다HttpContext.AllErrors. 이 예제에서는 메서드를 사용하여 세 가지 사용자 지정 예외를 AddError 만들고 속성을 사용하여 AllErrors 이러한 예외를 배열에 로드합니다. 그런 다음, 배열을 포함하는 페이지에 쓰고 메서드를 ClearError 사용하여 속성의 모든 오류를 Context 지웁니다.

     void Page_Load(Object sender,EventArgs e) 
     {
        Response.Write("<h3>Page.Context Example:</h3>");

        // Add three custom exceptions.
        Context.AddError(new Exception(
            "<h3 style='color: red'>New Exception #1.</h3>"));
        Context.AddError(new Exception(
            "<h3 style='color: red'>New Exception #2.</h3>"));
        Context.AddError(new Exception(
            "<h3 style='color: red'>New Exception #3.</h3>"));

        // Capture all the new Exceptions in an array.
        Exception[] errs = Context.AllErrors;

        foreach (Exception ex in errs)
        {
           Response.Write("<p style='text-align:center; ");
           Response.Write("font-weight:bold'>");
           Response.Write(Server.HtmlEncode(ex.ToString()) + "</p>"); 
        }

        // Clear the exceptions so ASP.NET won't handle them.
        Context.ClearError();
     }

     Sub Page_Load(Sender As Object, e As EventArgs ) 
     
        Response.Write("<h3>Page.Context Example:</h3>")
           
        ' Add three custom exceptions.
       Context.AddError(New Exception( _
           "<h3 style=""color: red"">New Exception #1.</h3>"))
       Context.AddError(New Exception( _
           "<h3 style=""color: red"">New Exception #2.</h3>"))
       Context.AddError(New Exception( _
           "<h3 style=""color: red"">New Exception #3.</h3>"))

        ' Capture all the new Exceptions in an array.
        Dim errs() As Exception = Context.AllErrors
        Dim ex As Exception
        
        For Each ex In errs
           Response.Write("<p style='text-align:center; font-weight:bold'>")
           Response.Write(Server.HtmlEncode(ex.ToString()) + "</p>")
        Next

        ' Clear the exceptions so ASP.NET won't handle them.
        Context.ClearError()
     End Sub

설명

이 속성은 요청, 응답, 세션 및 애플리케이션에 대 한 정보를 포함 하 여 페이지에서는 실행 컨텍스트를 프로그래밍 방식 액세스를 제공 합니다.

적용 대상

추가 정보