다음을 통해 공유


SessionStateUtility.RemoveHttpSessionStateFromContext(HttpContext) 메서드

정의

지정된 컨텍스트에서 세션 데이터를 제거합니다.

public:
 static void RemoveHttpSessionStateFromContext(System::Web::HttpContext ^ context);
public static void RemoveHttpSessionStateFromContext (System.Web.HttpContext context);
static member RemoveHttpSessionStateFromContext : System.Web.HttpContext -> unit
Public Shared Sub RemoveHttpSessionStateFromContext (context As HttpContext)

매개 변수

context
HttpContext

세션 데이터를 제거할 HttpContext입니다.

예제

다음 코드 예제에서는 사용자 지정 세션 상태 모듈에서 ReleaseRequestState 이벤트에 대 한 처리기를 보여 입니다. 이벤트 처리기는 현재 HttpContext에서 세션 데이터를 제거합니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 SessionStateUtility 클래스입니다.

//
// Event handler for HttpApplication.ReleaseRequestState
//

private void OnReleaseRequestState(object source, EventArgs args)
{
    HttpApplication app = (HttpApplication)source;
    HttpContext context = app.Context;
    string sessionID;

    // Read the session state from the context
    HttpSessionStateContainer stateProvider =
      (HttpSessionStateContainer)(SessionStateUtility.GetHttpSessionStateFromContext(context));

    // If Session.Abandon() was called, remove the session data from the local Hashtable
    // and execute the Session_OnEnd event from the Global.asax file.
    if (stateProvider.IsAbandoned)
    {
        try
        {
            pHashtableLock.AcquireWriterLock(Int32.MaxValue);

            sessionID = pSessionIDManager.GetSessionID(context);
            pSessionItems.Remove(sessionID);
        }
        finally
        {
            pHashtableLock.ReleaseWriterLock();
        }

        SessionStateUtility.RaiseSessionEnd(stateProvider, this, EventArgs.Empty);
    }

    SessionStateUtility.RemoveHttpSessionStateFromContext(context);
}
'
' Event handler for HttpApplication.ReleaseRequestState
'
Private Sub OnReleaseRequestState(ByVal [source] As Object, ByVal args As EventArgs)
    Dim app As HttpApplication = CType([source], HttpApplication)
    Dim context As HttpContext = app.Context
    Dim sessionID As String

    ' Read the session state from the context
    Dim stateProvider As HttpSessionStateContainer = _
       CType(SessionStateUtility.GetHttpSessionStateFromContext(context), HttpSessionStateContainer)

    ' If Session.Abandon() was called, remove the session data from the local Hashtable
    ' and execute the Session_OnEnd event from the Global.asax file.
    If stateProvider.IsAbandoned Then
        Try
            pHashtableLock.AcquireWriterLock(Int32.MaxValue)

            sessionID = pSessionIDManager.GetSessionID(context)
            pSessionItems.Remove(sessionID)
        Finally
            pHashtableLock.ReleaseWriterLock()
        End Try

        SessionStateUtility.RaiseSessionEnd(stateProvider, Me, EventArgs.Empty)
    End If

  SessionStateUtility.RemoveHttpSessionStateFromContext(context)
End Sub

설명

메서드는 RemoveHttpSessionStateFromContext 지정된 HttpContext에서 세션 데이터를 지웁니다. 세션 상태 모듈은 이벤트에 대한 처리기에서 메서드를 호출 RemoveHttpSessionStateFromContext 합니다 ReleaseRequestState .

적용 대상