SessionStateUtility.GetSessionStaticObjects メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SessionStateUtility.GetSessionStaticObjects メソッドの意味・解説 

SessionStateUtility.GetSessionStaticObjects メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定されコンテキスト静的オブジェクトコレクションへの参照取得します

名前空間: System.Web.SessionState
アセンブリ: 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 HttpStaticObjectsCollection GetSessionStaticObjects
 (
    HttpContext context
)
public:
static HttpStaticObjectsCollection^ GetSessionStaticObjects (
    HttpContext^ context
)
public static HttpStaticObjectsCollection GetSessionStaticObjects
 (
    HttpContext context
)
public static function GetSessionStaticObjects
 (
    context : HttpContext
) : HttpStaticObjectsCollection

パラメータ

context

静的オブジェクトコレクション取得元となる HttpContext。

戻り値
指定され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;
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SessionStateUtility クラス
SessionStateUtility メンバ
System.Web.SessionState 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「SessionStateUtility.GetSessionStaticObjects メソッド」の関連用語

SessionStateUtility.GetSessionStaticObjects メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SessionStateUtility.GetSessionStaticObjects メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS