SessionStateUtility.GetSessionStaticObjects(HttpContext) SessionStateUtility.GetSessionStaticObjects(HttpContext) SessionStateUtility.GetSessionStaticObjects(HttpContext) SessionStateUtility.GetSessionStaticObjects(HttpContext) Method

Definition

Ruft einen Verweis auf die Auflistung der statischen Objekte für den angegebenen Kontext ab.Gets a reference to the static objects collection for the specified context.

public:
 static System::Web::HttpStaticObjectsCollection ^ GetSessionStaticObjects(System::Web::HttpContext ^ context);
public static System.Web.HttpStaticObjectsCollection GetSessionStaticObjects (System.Web.HttpContext context);
static member GetSessionStaticObjects : System.Web.HttpContext -> System.Web.HttpStaticObjectsCollection
Public Shared Function GetSessionStaticObjects (context As HttpContext) As HttpStaticObjectsCollection

Parameter

context
HttpContext HttpContext HttpContext HttpContext

Der HttpContext, aus dem die Auflistung der statischen Objekte abgerufen werden soll.The HttpContext from which to get the static objects collection.

Gibt zurück

Eine mit dem HttpStaticObjectsCollection-Eigenschaftswert für den angegebenen StaticObjects gefüllte HttpContext-Auflistung.An HttpStaticObjectsCollection collection populated with the StaticObjects property value for the specified HttpContext.

Beispiele

Das folgende Codebeispiel zeigt den Handler für das AcquireRequestState -Ereignis in einem benutzerdefinierten Sitzungs Zustands Modul.The following code example shows the handler for the AcquireRequestState event in a custom session-state module. Das Modul ruft vorhandene Sitzungsinformationen ab oder erstellt neue Sitzungsinformationen, einschließlich der HttpStaticObjectsCollection von der GetSessionStaticObjects -Methode zurückgegebenen Auflistung, und fügt Sie HttpContext der der aktuellen Anforderung hinzu.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. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die SessionStateUtility -Klasse bereitgestellt wird.This code example is part of a larger example provided for the SessionStateUtility class.

//
// Event handler for HttpApplication.AcquireRequestState
//

private void OnAcquireRequestState(object source, EventArgs args)
{
    HttpApplication app = (HttpApplication)source;
    HttpContext context = app.Context;
    bool isNew = false;
    string sessionID;
    SessionItem sessionData = null;
    bool supportSessionIDReissue = true;

    pSessionIDManager.InitializeRequest(context, false, out supportSessionIDReissue);
    sessionID = pSessionIDManager.GetSessionID(context);


    if (sessionID != null)
    {
        try
        {
            pHashtableLock.AcquireReaderLock(Int32.MaxValue);
            sessionData = (SessionItem)pSessionItems[sessionID];

            if (sessionData != null)
               sessionData.Expires = DateTime.Now.AddMinutes(pTimeout);
        }
        finally
        {
            pHashtableLock.ReleaseReaderLock();
        }
    }
    else
    {
        bool redirected, cookieAdded;

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

        if (redirected)
            return;
    }

    if (sessionData == null)
    {
        // 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();
        }
    }

    // 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 && Start != null)
    {
        Start(this, EventArgs.Empty);
    }
}

//
// Event for Session_OnStart event in the Global.asax file.
//

public event EventHandler Start;
    '
    ' 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

Hinweise

Die GetSessionStaticObjects -Methode wird zum Abrufen der Auflistung statischer Objekte verwendet, die in der Datei Global. asax für die Anwendung ASP.net definiert sind.The GetSessionStaticObjects method is used to retrieve the collection of static objects defined in the Global.asax file for the ASP.NET application. Eine Sitzungs Zustands Modul-Implementierung stellt die zurückgegebene HttpStaticObjectsCollection Auflistung an die IHttpSessionState Implementierungs Instanz bereit, die dem aktuellen Kontext mithilfe der AddHttpSessionStateToContext -Methode hinzugefügt wird.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.

Kann auch die GetSessionStaticObjects -Methode verwenden, wenn ein SessionStateStoreData -Objekt erstellt wird. SessionStateStoreProviderBaseA SessionStateStoreProviderBase can also use the GetSessionStaticObjects method when creating a SessionStateStoreData object.

Gilt für: