HttpContext 클래스

정의

개별 HTTP 요청에 대한 HTTP 관련 정보를 모두 캡슐화합니다.

public ref class HttpContext sealed : IServiceProvider
public sealed class HttpContext : IServiceProvider
type HttpContext = class
    interface IServiceProvider
Public NotInheritable Class HttpContext
Implements IServiceProvider
상속
HttpContext
구현

예제

다음 예제에서는 개체의 HttpContext 속성에 액세스하고 표시하는 방법을 보여 줍니다. 현재 HTTP 요청의 컨텍스트는 개체의 속성을 사용하여 Context 액세스됩니다 Page .

<%@ 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">

    protected void Page_Load(object sender, EventArgs e)
    {
        // The HttpContext associated with the page can be accessed by the Context property.
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        // Use the current HttpContext object to determine if custom errors are enabled.
        sb.Append("Is custom errors enabled: " +
            Context.IsCustomErrorEnabled.ToString() + "<br/>");

        // Use the current HttpContext object to determine if debugging is enabled.
        sb.Append("Is debugging enabled: " +
            Context.IsDebuggingEnabled.ToString() + "<br/>");

        // Use the current HttpContext object to access the current TraceContext object.
        sb.Append("Trace Enabled: " +
            Context.Trace.IsEnabled.ToString() + "<br/>");

        // Use the current HttpContext object to access the current HttpApplicationState object.
        sb.Append("Number of items in Application state: " +
            Context.Application.Count.ToString() + "<br/>");

        // Use the current HttpContext object to access the current HttpSessionState object.
        // Session state may not be configured.
        try
        {
            sb.Append("Number of items in Session state: " +
                Context.Session.Count.ToString() + "<br/>");
        }
        catch
        {
            sb.Append("Session state not enabled. <br/>");
        }

        // Use the current HttpContext object to access the current Cache object.
        sb.Append("Number of items in the cache: " +
            Context.Cache.Count.ToString() + "<br/>");

        // Use the current HttpContext object to determine the timestamp for the current HTTP Request.
        sb.Append("Timestamp for the HTTP request: " +
            Context.Timestamp.ToString() + "<br/>");

        // Assign StringBuilder object to output label.
        OutputLabel.Text = sb.ToString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HttpContext Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       Using the current HttpContext to get information about the current page.
       <br />
       <asp:Label id="OutputLabel" 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">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        ' The HttpContext associated with the page can be accessed by the Context property.
        Dim sb As New System.Text.StringBuilder()

        ' Use the current HttpContext object to determine if custom errors are enabled.
        sb.Append("Is custom errors enabled: " & _
            Context.IsCustomErrorEnabled.ToString() & "<br/>")

        ' Use the current HttpContext object to determine if debugging is enabled.
        sb.Append("Is debugging enabled: " & _
            Context.IsDebuggingEnabled.ToString() & "<br/>")

        ' Use the current HttpContext object to access the current TraceContext object.
        sb.Append("Trace Enabled: " & _
            Context.Trace.IsEnabled.ToString() & "<br/>")

        ' Use the current HttpContext object to access the current HttpApplicationState object.
        sb.Append("Number of items in Application state: " & _
            Context.Application.Count.ToString() & "<br/>")

        ' Use the current HttpContext object to access the current HttpSessionState object.
        ' Session state may not be configured.
        Try
            sb.Append("Number of items in Session state: " & _
                Context.Session.Count.ToString() & "<br/>")
        Catch ex As Exception
            sb.Append("Session state not enabled. <br/>")
        End Try

        ' Use the current HttpContext object to access the current Cache object.
        sb.Append("Number of items in the cache: " & _
            Context.Cache.Count.ToString() & "<br/>")

        ' Use the current HttpContext object to determine the timestamp for the current HTTP Request.
        sb.Append("Timestamp for the HTTP request: " & _
            Context.Timestamp.ToString() & "<br/>")

        ' Assign StringBuilder object to output label.
        OutputLabel.Text = sb.ToString()
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HttpContext Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       Using the current HttpContext to get information about the current page.
       <br />
       <asp:Label id="OutputLabel" runat="server"></asp:Label>           
    </div>
    </form>
</body>
</html>

설명

상속 IHttpModule 되는 클래스 및 IHttpHandler 인터페이스는 현재 HTTP 요청에 대한 개체에 대한 참조 HttpContext 를 제공합니다. 개체는 요청에 대한 내장 RequestResponse속성 및 Server 속성에 대한 액세스를 제공합니다.

중요

이 개체는 완료되면 가비지 수집할 HttpRequest 준비가 된 것입니다. 요청이 완료된 후의 사용은 다음과 같이 정의되지 않은 동작으로 NullReferenceException이어질 수 있습니다.

이 개체는 ASP.NET 의해 제어되는 스레드에서만 사용할 수 있습니다. 백그라운드 스레드에서의 사용은 정의되지 않은 동작으로 이어질 수 있습니다.

생성자

HttpContext(HttpRequest, HttpResponse)

지정된 요청과 응답 개체를 사용하여 HttpContext 클래스의 새 인스턴스를 초기화합니다.

HttpContext(HttpWorkerRequest)

지정된 작업자 요청 개체를 사용하는 HttpContext 클래스의 새 인스턴스를 초기화합니다.

속성

AllErrors

HTTP 요청을 처리하는 동안 누적된 오류의 배열을 가져옵니다.

AllowAsyncDuringSyncStages

비동기 작업을 예상하지 못한 경우 ASP.NET 요청의 일부를 처리하는 중에 비동기 작업이 허용되는지 여부를 나타내는 값을 가져오거나 설정합니다.

Application

현재 HTTP 요청에 대한 HttpApplicationState 개체를 가져옵니다.

ApplicationInstance

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

AsyncPreloadMode

비동기 미리 로드 모드와 관련된 플래그를 포함하는 개체를 가져오거나 설정합니다.

Cache

현재 애플리케이션 도메인에 대한 Cache 개체를 가져옵니다.

Current

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

CurrentHandler

현재 실행 중인 처리기를 나타내는 IHttpHandler 개체를 가져옵니다.

CurrentNotification

현재 처리 중인 HttpApplication 이벤트를 나타내는 RequestNotification 값을 가져옵니다.

Error

HTTP 요청을 처리하는 동안 누적된 오류가 있으면 첫 번째 오류를 가져옵니다.

Handler

HTTP 요청을 처리하는 IHttpHandler 개체를 가져오거나 설정합니다.

IsCustomErrorEnabled

현재 HTTP 요청에 대해 사용자 지정 오류를 사용할 수 있는지 여부를 나타내는 값을 가져옵니다.

IsDebuggingEnabled

현재 HTTP 요청이 디버그 모드인지 여부를 나타내는 값을 가져옵니다.

IsPostNotification

HttpApplication 이벤트가 처리를 완료한 직후 ASP.NET 파이프라인의 현재 처리 지점인 값을 가져옵니다.

IsWebSocketRequest

요청에 AspNetWebSocket 요청이 있는지 여부를 나타내는 값을 가져옵니다.

IsWebSocketRequestUpgrading

연결이 HTTP 연결에서 AspNetWebSocket 연결로 업그레이드되고 있는지 여부를 나타내는 값을 가져옵니다.

Items

HTTP 요청을 수행하는 동안 IHttpModule 인터페이스와 IHttpHandler 인터페이스 간에 데이터를 구성하고 공유하는 데 사용할 수 있는 키/값 컬렉션을 가져옵니다.

PageInstrumentation

이 요청에 대한 페이지 계측 서비스 인스턴스에 대한 참조를 가져옵니다.

PreviousHandler

부모 처리기에 대한 IHttpHandler 개체를 가져옵니다.

Profile

현재 사용자 프로필에 대한 ProfileBase 개체를 가져옵니다.

Request

현재 HTTP 요청에 대한 HttpRequest 개체를 가져옵니다.

Response

현재 HTTP 응답에 대한 HttpResponse 개체를 가져옵니다.

Server

처리하고 있는 웹 요청에 사용되는 메서드를 제공하는 HttpServerUtility 개체를 가져옵니다.

Session

현재 HTTP 요청에 대한 HttpSessionState 개체를 가져옵니다.

SkipAuthorization

UrlAuthorizationModule 개체가 현재 요청에 대한 인증 확인을 건너뛰어야 하는지 여부를 지정하는 값을 가져오거나 설정합니다.

ThreadAbortOnTimeout

요청 시간이 경과될 경우 이 요청을 서비스 중인 스레드에서 ASP.NET 런타임이 Abort()를 호출해야 하는지 여부를 지정하는 값을 가져오거나 설정합니다.

Timestamp

현재 HTTP 요청의 초기 타임스탬프를 가져옵니다.

Trace

현재 HTTP 응답에 대한 TraceContext 개체를 가져옵니다.

User

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

WebSocketNegotiatedProtocol

AspNetWebSocket 연결을 위해 서버에서 클라이언트로 전송된 협상된 프로토콜을 가져옵니다.

WebSocketRequestedProtocols

클라이언트에서 요청한 프로토콜의 순서 있는 목록을 가져옵니다.

메서드

AcceptWebSocketRequest(Func<AspNetWebSocketContext,Task>)

지정된 사용자 함수를 사용하는 AspNetWebSocket 요청을 허용합니다.

AcceptWebSocketRequest(Func<AspNetWebSocketContext,Task>, AspNetWebSocketOptions)

지정된 사용자 함수 및 옵션 개체를 사용하는 AspNetWebSocket 요청을 허용합니다.

AddError(Exception)

현재 HTTP 요청에 대한 예외 컬렉션에 예외를 추가합니다.

AddOnRequestCompleted(Action<HttpContext>)

요청의 HTTP 부분이 종료될 때 발생하는 가상 이벤트를 발생시킵니다.

ClearError()

현재 HTTP 요청에 대한 오류를 모두 지웁니다.

DisposeOnPipelineCompleted(IDisposable)

이 요청의 Dispose() 연결 부분이 완료될 때 호출할 개체의 AspNetWebSocket 메서드를 사용하도록 설정합니다.

Equals(Object)

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

(다음에서 상속됨 Object)
GetAppConfig(String)
사용되지 않습니다.

현재 애플리케이션에 대해 요청된 구성 정보를 반환합니다.

GetConfig(String)
사용되지 않습니다.

현재 HTTP 요청에 대해 요청된 구성 정보를 반환합니다.

GetGlobalResourceObject(String, String)

지정된 ClassKeyResourceKey 속성에 따라 애플리케이션 수준의 리소스 개체를 가져옵니다.

GetGlobalResourceObject(String, String, CultureInfo)

지정된 ClassKeyResourceKey 속성과 CultureInfo 개체에 따라 애플리케이션 수준의 리소스 개체를 가져옵니다.

GetHashCode()

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

(다음에서 상속됨 Object)
GetLocalResourceObject(String, String)

지정된 VirtualPathResourceKey 속성에 따라 페이지 수준의 리소스 개체를 가져옵니다.

GetLocalResourceObject(String, String, CultureInfo)

지정된 VirtualPathResourceKey 속성과 CultureInfo 개체에 따라 페이지 수준의 리소스 개체를 가져옵니다.

GetSection(String)

현재 애플리케이션의 기본 구성에 대해 지정된 구성 섹션을 가져옵니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

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

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

(다음에서 상속됨 Object)
RemapHandler(IHttpHandler)

요청에 대한 처리기를 지정할 수 있습니다.

RewritePath(String)

지정한 경로를 사용하여 URL을 다시 작성합니다.

RewritePath(String, Boolean)

지정된 경로와 서버 리소스의 가상 경로가 수정되었는지 여부를 지정하는 부울 값을 사용하여 URL을 다시 작성합니다.

RewritePath(String, String, String)

지정된 경로, 경로 정보 및 쿼리 문자열 정보를 사용하여 URL을 다시 작성합니다.

RewritePath(String, String, String, Boolean)

지정된 가상 경로, 경로 정보, 쿼리 문자열 정보 및 클라이언트 파일 경로가 다시 작성 경로로 설정되었는지 여부를 지정하는 부울 값을 사용하여 URL을 다시 작성합니다.

SetSessionStateBehavior(SessionStateBehavior)

HTTP 요청을 지원하기 위해 필요한 세션 상태 동작의 유형을 설정합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

IServiceProvider.GetService(Type)

현재 서비스 형식에 대한 개체를 반환합니다.

적용 대상

추가 정보