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

Public Shared Function GetHttpSessionStateFromContext ( _ context As HttpContext _ ) As IHttpSessionState
Dim context As HttpContext Dim returnValue As IHttpSessionState returnValue = SessionStateUtility.GetHttpSessionStateFromContext(context)
戻り値
現在の要求のセッション データを含む IHttpSessionState の実装のインスタンス。

GetHttpSessionStateFromContext メソッドは、セッション状態モジュールがセッション データを現在の要求から取得するために使用します。これは、要求の最後の ReleaseRequestState イベントで行います。返されたセッション データは、セッション データ ストアに書き込むことができます。セッションが破棄されると、セッション データをデータ ストアから削除できるようになり、HttpContext と Session_OnEnd イベントを実行できます。
実装時の注意 RemoveHttpSessionStateFromContext メソッドを使用して内部ストアからセッション データを削除し、RaiseSessionEnd メソッドを使用して Session_OnEnd イベントを生成します。
カスタムのセッション状態モジュールの ReleaseRequestState イベントのハンドラのコード例を次に示します。このモジュールは、GetHttpSessionStateFromContext メソッドを使用して現在の要求の 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.GetHttpSessionStateFromContext メソッドのページへのリンク