Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SessionStateUtility.GetSessionStaticObjects Method

Gets a reference to the static objects collection for the specified context.

Namespace:  System.Web.SessionState
Assembly:  System.Web (in System.Web.dll)
'Declaration
Public Shared Function GetSessionStaticObjects ( _
	context As HttpContext _
) As HttpStaticObjectsCollection

Parameters

context
Type: System.Web.HttpContext

The HttpContext from which to get the static objects collection.

Return Value

Type: System.Web.HttpStaticObjectsCollection
An HttpStaticObjectsCollection collection populated with the StaticObjects property value for the specified HttpContext.

The GetSessionStaticObjects method is used to retrieve the collection of static objects defined in the Global.asax file for the ASP.NET application. A session-state module implementation will supply the returned HttpStaticObjectsCollection collection to the IHttpSessionState implementation instance that is added to the current context using the AddHttpSessionStateToContext method.

A SessionStateStoreProviderBase can also use the GetSessionStaticObjects method when creating a SessionStateStoreData object.

The following code example shows the handler for the AcquireRequestState event in a custom session-state module. The module retrieves existing session information or creates new session information, including the HttpStaticObjectsCollection collection returned from the GetSessionStaticObjects method, and adds it to the HttpContext of the current request. This code example is part of a larger example provided for the SessionStateUtility class.

        
        ' Event handler for HttpApplication.AcquireRequestState 
        
        Private Sub OnAcquireRequestState(ByVal [source] As Object, ByVal args As EventArgs)
            Dim app As HttpApplication = CType([source], HttpApplication)
            Dim context As HttpContext = app.Context
            Dim isNew As Boolean = False 
            Dim sessionID As String 
            Dim sessionData As SessionItem = Nothing 
            Dim supportSessionIDReissue As Boolean = True

            pSessionIDManager.InitializeRequest(context, False, supportSessionIDReissue)
            sessionID = pSessionIDManager.GetSessionID(context)


            If Not (sessionID Is Nothing) Then 
                Try
                    pHashtableLock.AcquireReaderLock(Int32.MaxValue)
                    sessionData = CType(pSessionItems(sessionID), SessionItem)

                    If Not (sessionData Is Nothing) Then
                        sessionData.Expires = DateTime.Now.AddMinutes(pTimeout)
                    End If 
                Finally
                    pHashtableLock.ReleaseReaderLock()
                End Try 
            Else 
                Dim redirected, cookieAdded As Boolean

                sessionID = pSessionIDManager.CreateSessionID(context)
                pSessionIDManager.SaveSessionID(context, sessionID, redirected, cookieAdded)

                If redirected Then Return 
            End If 
            If sessionData 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

                sessionData = New SessionItem()

                sessionData.Items = New SessionStateItemCollection()
                sessionData.StaticObjects = SessionStateUtility.GetSessionStaticObjects(context)
                sessionData.Expires = DateTime.Now.AddMinutes(pTimeout)

                Try
                    pHashtableLock.AcquireWriterLock(Int32.MaxValue)
                    pSessionItems(sessionID) = sessionData
                Finally
                    pHashtableLock.ReleaseWriterLock()
                End Try 
            End If 

            ' Add the session data to the current HttpContext.
            SessionStateUtility.AddHttpSessionStateToContext(context, _
                             New HttpSessionStateContainer(sessionID, _
                                                          sessionData.Items, _
                                                          sessionData.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

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.