HttpContext.Current 속성

정의

현재 HTTP 요청에 대한 HttpContext 개체를 가져오거나 설정합니다.

public:
 static property System::Web::HttpContext ^ Current { System::Web::HttpContext ^ get(); void set(System::Web::HttpContext ^ value); };
public static System.Web.HttpContext Current { get; set; }
member this.Current : System.Web.HttpContext with get, set
Public Shared Property Current As HttpContext

속성 값

HttpContext

현재 HTTP 요청에 대한 HttpContext 인스턴스입니다.

예제

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

protected void Page_Load(object sender, EventArgs e)
{
    HttpContext context = HttpContext.Current;
    Response.Write("<p>HttpContext.Current Example:</p>");

    // Add three custom exceptions.
    context.AddError(new Exception("New Exception #1"));
    context.AddError(new Exception("New Exception #2"));
    context.AddError(new Exception("New Exception #3"));

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

    foreach (Exception ex in errs)
    {
        Response.Write("<p>" + Server.HtmlEncode(ex.ToString()) + "</p>");
    }

    // Clear the exceptions so ASP.NET won't handle them.
    context.ClearError();
}
Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim context As HttpContext = HttpContext.Current
Response.Write("<p>HttpContext.Current Example:</p>")

' Add three custom exceptions.
context.AddError(New Exception("New Exception #1"))
context.AddError(New Exception("New Exception #2"))
context.AddError(New Exception("New Exception #3"))

' Capture all the new Exceptions in an array.
Dim errs As Exception() = context.AllErrors

For Each ex As Exception In errs
Response.Write("<p>" & Server.HtmlEncode(ex.ToString()) & "</p>")
Next

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

설명

이 속성은 클래스의 정적 속성입니다 HttpContext . 속성은 현재 요청에 적용되는 인스턴스를 저장 HttpContext 합니다. 이 인스턴스의 속성은 클래스의 비정적 속성입니다 HttpContext .

이 속성을 사용하여 Page.Context 현재 HTTP 요청에 대한 개체에 액세스할 HttpContext 수도 있습니다.

적용 대상

추가 정보