다음을 통해 공유


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 의해 제어되는 스레드에서만 사용할 수 있습니다. 백그라운드 스레드에서의 사용은 정의되지 않은 동작으로 이어질 수 있습니다.

생성자

Name Description
HttpContext(HttpRequest, HttpResponse)

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

HttpContext(HttpWorkerRequest)

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

속성

Name Description
AllErrors

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

AllowAsyncDuringSyncStages

ASP.NET 요청 처리 중에 비동기 작업이 허용되지 않을 때 허용되는지 여부를 나타내는 값을 가져오거나 설정합니다.

Application

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

ApplicationInstance

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

AsyncPreloadMode

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

Cache

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

Current

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

CurrentHandler

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

CurrentNotification

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

Error

HTTP 요청 처리 중에 누적된 첫 번째 오류(있는 경우)를 가져옵니다.

Handler

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

IsCustomErrorEnabled

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

IsDebuggingEnabled

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

IsPostNotification

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

IsWebSocketRequest

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

IsWebSocketRequestUpgrading

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

Items

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

PageInstrumentation

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

PreviousHandler

IHttpHandler 부모 처리기의 개체를 가져옵니다.

Profile

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

Request

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

Response

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

Server

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

Session

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

SkipAuthorization

개체가 현재 요청에 대한 권한 부여 검사를 건너뛸지 여부를 UrlAuthorizationModule 지정하는 값을 가져오거나 설정합니다.

ThreadAbortOnTimeout

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

Timestamp

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

Trace

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

User

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

WebSocketNegotiatedProtocol

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

WebSocketRequestedProtocols

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

메서드

Name Description
AcceptWebSocketRequest(Func<AspNetWebSocketContext,Task>, AspNetWebSocketOptions)

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

AcceptWebSocketRequest(Func<AspNetWebSocketContext,Task>)

지정된 사용자 함수를 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, CultureInfo)

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

GetGlobalResourceObject(String, String)

지정된 속성과 ResourceKey 속성을 기반으로 하는 애플리케이션 수준 리소스 개체를 ClassKey 가져옵니다.

GetHashCode()

기본 해시 함수로 사용됩니다.

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

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

GetLocalResourceObject(String, String)

지정한 속성과 ResourceKey 속성에 따라 페이지 수준 리소스 개체를 VirtualPath 가져옵니다.

GetSection(String)

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

GetType()

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

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

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

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

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

RewritePath(String, Boolean)

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

RewritePath(String, String, String, Boolean)

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

RewritePath(String, String, String)

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

RewritePath(String)

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

SetSessionStateBehavior(SessionStateBehavior)

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

ToString()

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

(다음에서 상속됨 Object)

명시적 인터페이스 구현

Name Description
IServiceProvider.GetService(Type)

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

적용 대상

추가 정보