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

Public Shared Function GetSessionStaticObjects ( _ context As HttpContext _ ) As HttpStaticObjectsCollection
Dim context As HttpContext Dim returnValue As HttpStaticObjectsCollection returnValue = SessionStateUtility.GetSessionStaticObjects(context)
public static function GetSessionStaticObjects ( context : HttpContext ) : HttpStaticObjectsCollection
戻り値
指定された HttpContext の StaticObjects プロパティ値を含む HttpStaticObjectsCollection コレクション。

GetSessionStaticObjects メソッドを使用して、ASP.NET アプリケーションの Global.asax ファイルに定義されている静的オブジェクトのコレクションを取得します。セッション状態モジュールの実装は、返された HttpStaticObjectsCollection コレクションを IHttpSessionState の実装のインターフェイスに提供します。このインターフェイスは、AddHttpSessionStateToContext メソッドを使用して現在のコンテキストに追加します。
SessionStateStoreProviderBase は、SessionStateStoreData オブジェクトを作成するときに GetSessionStaticObjects メソッドも使用できます。

カスタムのセッション状態モジュールの AcquireRequestState イベントのハンドラのコード例を次に示します。このモジュールは、GetSessionStaticObjects メソッドが返す HttpStaticObjectsCollection コレクションを含めて、既存のセッション情報を取得するか、または新しいセッションの情報を作成し、現在の要求の HttpContext に追加します。このコード例は、SessionStateUtility クラスのトピックで取り上げているコード例の一部分です。
' ' Event handler for HttpApplication.AcquireRequestState ' Private Sub OnAcquireRequestState(source As Object, args As EventArgs) Dim app As HttpApplication = CType(source, HttpApplication) Dim context As HttpContext = app.Context Dim isNew As Boolean = False pSessionData = Nothing pSessionID = pSessionIDManager.GetSessionID(context) If Not pSessionID Is Nothing Then Try pHashtableLock.AcquireReaderLock(Int32.MaxValue) pSessionData = CType(pSessionItems(pSessionID), SessionItem) If Not pSessionData Is Nothing Then _ pSessionData.Expires = DateTime.Now.AddMinutes(pTimeout) Finally pHashtableLock.ReleaseReaderLock() End Try Else Dim redirected, cookieAdded As Boolean pSessionID = pSessionIDManager.CreateSessionID(context) pSessionIDManager.SaveSessionID(context, pSessionID, redirected, cookieAdded) If redirected Then Return End If If pSessionData Is Nothing Then ' Identify the session as a New session state instance. Create a New SessionItem ' and add it to the local Hashtable. isNew = True pSessionData = New SessionItem() pSessionData.Items = New SessionStateItemCollection() pSessionData.StaticObjects = SessionStateUtility.GetSessionStaticObjects(context) pSessionData.Expires = DateTime.Now.AddMinutes(pTimeout) Try pHashtableLock.AcquireWriterLock(Int32.MaxValue) pSessionItems(pSessionID) = pSessionData Finally pHashtableLock.ReleaseWriterLock() End Try End If ' Add the session data to the current HttpContext. SessionStateUtility.AddHttpSessionStateToContext(context, _ New HttpSessionStateContainer(pSessionID, _ pSessionData.Items, _ pSessionData.StaticObjects, _ pTimeout, _ isNew, _ pCookieMode, _ SessionStateMode.Custom, _ False)) ' Execute the Session_OnStart event for a New session. If isNew Then RaiseEvent Start(Me, EventArgs.Empty) End Sub ' ' Event for Session_OnStart event in the Global.asax file. ' Public Event Start As EventHandler
// // Event handler for HttpApplication.AcquireRequestState // private void OnAcquireRequestState(object source, EventArgs args) { HttpApplication app = (HttpApplication)source; HttpContext context = app.Context; bool isNew = false; pSessionData = null; pSessionID = pSessionIDManager.GetSessionID(context); if (pSessionID != null) { try { pHashtableLock.AcquireReaderLock(Int32.MaxValue); pSessionData = (SessionItem)pSessionItems[pSessionID]; if (pSessionData != null) pSessionData.Expires = DateTime.Now.AddMinutes(pTimeout); } finally { pHashtableLock.ReleaseReaderLock(); } } else { bool redirected, cookieAdded; pSessionID = pSessionIDManager.CreateSessionID(context); pSessionIDManager.SaveSessionID(context, pSessionID, out redirected, out cookieAdded); if (redirected) return; } if (pSessionData == null) { // Identify the session as a new session state instance. Create a new SessionItem // and add it to the local Hashtable. isNew = true; pSessionData = new SessionItem(); pSessionData.Items = new SessionStateItemCollection(); pSessionData.StaticObjects = SessionStateUtility.GetSessionStaticObjects(context); pSessionData.Expires = DateTime.Now.AddMinutes(pTimeout); try { pHashtableLock.AcquireWriterLock(Int32.MaxValue); pSessionItems[pSessionID] = pSessionData; } finally { pHashtableLock.ReleaseWriterLock(); } } // Add the session data to the current HttpContext. SessionStateUtility.AddHttpSessionStateToContext(context, new HttpSessionStateContainer(pSessionID, pSessionData.Items, pSessionData.StaticObjects, pTimeout, isNew, pCookieMode, SessionStateMode.Custom, false)); // Execute the Session_OnStart event for a new session. if (isNew && Start != null) { Start(this, EventArgs.Empty); } } // // Event for Session_OnStart event in the Global.asax file. // public event EventHandler Start;

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.GetSessionStaticObjects メソッドのページへのリンク