SessionStateUtility.RemoveHttpSessionStateFromContext メソッド
アセンブリ: System.Web (system.web.dll 内)


RemoveHttpSessionStateFromContext メソッドは指定された HttpContext からセッション データをクリアします。セッション状態モジュールは、ReleaseRequestState イベントのハンドラで RemoveHttpSessionStateFromContext メソッドを呼び出します。

カスタムのセッション状態モジュールの ReleaseRequestState イベントのハンドラのコード例を次に示します。このイベント ハンドラは、現在の HttpContext からセッション データを削除します。このコード例は、SessionStateUtility クラスのトピックで取り上げているコード例の一部分です。
' ' Event handler for HttpApplication.ReleaseRequestState ' Private Sub OnReleaseRequestState(source As Object, args As EventArgs) Dim app As HttpApplication = CType(source, HttpApplication) Dim context As HttpContext = app.Context ' 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) pSessionItems.Remove(pSessionID) Finally pHashtableLock.ReleaseWriterLock() End Try SessionStateUtility.RaiseSessionEnd(stateProvider, Me, EventArgs.Empty) End If SessionStateUtility.RemoveHttpSessionStateFromContext(context) End Sub
// // Event handler for HttpApplication.ReleaseRequestState // private void OnReleaseRequestState(object source, EventArgs args) { HttpApplication app = (HttpApplication)source; HttpContext context = app.Context; // 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); pSessionItems.Remove(pSessionID); } finally { pHashtableLock.ReleaseWriterLock(); } SessionStateUtility.RaiseSessionEnd(stateProvider, this, EventArgs.Empty); } SessionStateUtility.RemoveHttpSessionStateFromContext(context); }

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SessionStateUtility.RemoveHttpSessionStateFromContext メソッドのページへのリンク