IHttpSessionStateとは? わかりやすく解説

IHttpSessionState インターフェイス

メモ : このインターフェイスは、.NET Framework version 2.0新しく追加されたものです。

カスタムセッション状態コンテナ実装するコントラクト定義します

名前空間: System.Web.SessionState
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Interface IHttpSessionState
Dim instance As IHttpSessionState
public interface IHttpSessionState
public interface class IHttpSessionState
public interface IHttpSessionState
public interface IHttpSessionState
解説解説

セッション状態コンテナによって、現在のセッションセッション状態値と関連情報アクセスできますセッション状態コンテナ含まれるセッション情報は、Session プロパティ使用し、HttpSessionState クラスを介してアプリケーション コード公開されます。HttpSessionState クラスは、セッション状態コンテナラッパー クラスです。

セッション状態コンテナASP.NET実装は HttpSessionStateContainer クラスです。要求開始時の AcquireRequestState イベントで、SessionStateModule は HttpSessionStateContainer オブジェクト作成して値を格納し現在の HttpContext に割り当てます要求最後の ReleaseRequestState イベントで、SessionStateModule現在の HttpContext から HttpSessionStateContainer オブジェクト取得しセッション値をセッション ストア書き込むセッション破棄するなどの必要な処理を実行しますリダイレクトなどによって要求が突然終了した場合SessionStateModule は EndRequest メソッド呼び出して同じクリーンアップ実行します

カスタムセッション状態コンテナ作成するには、IHttpSessionState インターフェイス実装するクラス作成しますカスタムセッション状態コンテナ作成する場合は、SessionStateModuleカスタム モジュール置き換える必要がありますカスタム モジュールカスタムセッション状態コンテナインスタンス作成し、AddHttpSessionStateToContext メソッド使用して現在の HttpContext追加しますカスタムセッション状態モジュール例については、SessionStateUtility クラス概要参照してください

使用例使用例

IHttpSessionState インターフェイス実装し、MySessionState という新しセッション状態コンテナクラス作成するコード例次に示します

Imports System
Imports System.Web
Imports System.Web.SessionState
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Text
Imports System.Threading
Imports System.Globalization

Namespace Samples.AspNet.SessionState

  Public NotInheritable Class
 MySessionState
    Implements IHttpSessionState
  
    Const MAX_TIMEOUT As Integer
 = 24 * 60  ' Timeout cannot exceed 24 hours.

    Dim pId            As String
    Dim pSessionItems  As ISessionStateItemCollection
    Dim pStaticObjects As HttpStaticObjectsCollection
    Dim pTimeout       As Integer
    Dim pNewSession    As Boolean
    Dim pCookieMode    As HttpCookieMode
    Dim pMode          As SessionStateMode
    Dim pAbandon       As Boolean
    Dim pIsReadonly    As Boolean

    Public Sub New(id  
          As String, _
                   sessionItems  As ISessionStateItemCollection,
 _
                   staticObjects As HttpStaticObjectsCollection,
 _
                   timeout       As Integer,
 _
                   newSession    As Boolean,
 _
                   cookieMode    As HttpCookieMode, _
                   mode          As SessionStateMode, _  
                   isReadonly As Boolean)
    
      pId            = id   
      pSessionItems  = sessionItems
      pStaticObjects = staticObjects
      pTimeout       = timeout    
      pNewSession    = newSession 
      pCookieMode    = cookieMode
      pMode          = mode
      pIsReadonly    = isReadonly
    End Sub


    Public Property Timeout As
 Integer Implements IHttpSessionState.Timeout
      Get
        Return pTimeout
      End Get
      Set
        If value <= 0 Then _
          Throw New ArgumentException("Timeout
 value must be greater than zero.")

        If value > MAX_TIMEOUT Then _
          Throw New ArgumentException("Timout
 cannot be greater than " & MAX_TIMEOUT.ToString())

        pTimeout = value
      End Set
    End Property


    Public ReadOnly Property
 SessionID As String Implements
 IHttpSessionState.SessionID
      Get
        Return pId
      End Get
    End Property


    Public ReadOnly Property
 IsNewSession As Boolean Implements
 IHttpSessionState.IsNewSession
      Get
        Return pNewSession
      End Get
    End Property


    Public ReadOnly Property
 Mode As SessionStateMode Implements IHttpSessionState.Mode
    
      Get
        Return pMode
      End Get
    End Property


    Public ReadOnly Property
 IsCookieless As Boolean Implements
 IHttpSessionState.IsCookieLess    
      Get
        Return CookieMode = HttpCookieMode.UseUri
      End Get
    End Property


    Public ReadOnly Property
 CookieMode As HttpCookieMode Implements IHttpSessionState.CookieMode
    
      Get
        Return pCookieMode
      End Get
    End Property


    '
    ' Abandon marks the session as abandoned. The IsAbandoned property
 is used by the
    ' session state module to perform the abandon work during the ReleaseRequestState
 event.
    '
    Public Sub Abandon() Implements
 IHttpSessionState.Abandon
      pAbandon = True
    End Sub

    Public ReadOnly Property
 IsAbandoned As Boolean  
      Get
        Return pAbandon
      End Get
    End Property

    '
        ' Session.LCID exists only to support legacy ASP compatibility.
 ASP.NET developers should use
    ' Page.LCID instead.
    '
    Public Property LCID As
 Integer Implements IHttpSessionState.LCID
      Get
        Return Thread.CurrentThread.CurrentCulture.LCID
      End Get
      Set
        Thread.CurrentThread.CurrentCulture = CultureInfo.ReadOnly(new
 CultureInfo(value))
      End Set
    End Property


    '
        ' Session.CodePage exists only to support legacy ASP compatibility.
 ASP.NET developers should use
    ' Response.ContentEncoding instead.
    '
    Public Property CodePage As
 Integer Implements IHttpSessionState.CodePage
    
      Get
        If Not HttpContext.Current Is
 Nothing Then
          Return HttpContext.Current.Response.ContentEncoding.CodePage
        Else
          Return Encoding.Default.CodePage
        End If
      End Get
      Set       
        If Not HttpContext.Current Is
 Nothing Then _
          HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding(value)
      End Set
    End Property


    Public ReadOnly Property
 StaticObjects As HttpStaticObjectsCollection _
      Implements IHttpSessionState.StaticObjects
    
      Get
        Return pStaticObjects
      End Get
    End Property


    Public Property Item(name As
 String) As Object Implements
 IHttpSessionState.Item
      Get
        Return pSessionItems(name)
      End Get
      Set
        pSessionItems(name) = value
      End Set
    End Property


    Public Property Item(index As
 Integer) As Object Implements
 IHttpSessionState.Item    
      Get
        Return pSessionItems(index)
      End Get
      Set
        pSessionItems(index) = value
      End Set
    End Property
        

    Public Sub Add(name As
 String, value As Object)
 Implements IHttpSessionState.Add    
      pSessionItems(name) = value        
    End Sub


    Public Sub Remove(name As
 String) Implements IHttpSessionState.Remove
    
      pSessionItems.Remove(name)
    End Sub


    Public Sub RemoveAt(index As
 Integer) Implements IHttpSessionState.RemoveAt
    
      pSessionItems.RemoveAt(index)
    End Sub


    Public Sub Clear() Implements
 IHttpSessionState.Clear 
      pSessionItems.Clear()
    End Sub

    Public Sub RemoveAll() Implements
 IHttpSessionState.RemoveAll
        Clear()
    End Sub



    Public ReadOnly Property
 Count As Integer Implements
 IHttpSessionState.Count    
      Get
        Return pSessionItems.Count
      End Get
    End Property



    Public ReadOnly Property
 Keys As NameObjectCollectionBase.KeysCollection _
      Implements IHttpSessionState.Keys
    
      Get
        Return pSessionItems.Keys
      End Get
    End Property


    Public Function GetEnumerator() As
 IEnumerator Implements IHttpSessionState.GetEnumerator
        Return pSessionItems.GetEnumerator()
    End Function


    Public Sub CopyTo(items As
 Array, index As Integer) Implements
 IHttpSessionState.CopyTo    
      For Each o As Object
 In items
        items.SetValue(o, index)
        index += 1
      Next
    End Sub


    Public ReadOnly Property
 SyncRoot As Object Implements
 IHttpSessionState.SyncRoot    
        Get
          Return Me
       End Get
    End Property


    Public ReadOnly Property
 IsReadOnly As Boolean Implements
 IHttpSessionState.IsReadOnly    
      Get
        Return pIsReadonly
      End Get
    End Property


    Public ReadOnly Property
 IsSynchronized As Boolean Implements
 IHttpSessionState.IsSynchronized    
      Get
        Return False
      End Get
    End Property
  End Class
End Namespace
using System;
using System.Web;
using System.Web.SessionState;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Threading;
using System.Globalization;

namespace Samples.AspNet.SessionState
{
  public sealed class MySessionState : IHttpSessionState
  {
    const int MAX_TIMEOUT = 24 * 60;  //
 Timeout cannot exceed 24 hours.

    string                      pId;
    ISessionStateItemCollection pSessionItems;
    HttpStaticObjectsCollection pStaticObjects;
    int                         pTimeout;
    bool                        pNewSession;
    HttpCookieMode              pCookieMode;
    SessionStateMode            pMode;
    bool                        pAbandon;
    bool                        pIsReadonly;

    public MySessionState(string          
            id, 
                          ISessionStateItemCollection sessionItems,
                          HttpStaticObjectsCollection staticObjects,
                          int                         timeout
,
                          bool                        newSession
,
                          HttpCookieMode              cookieMode,
                          SessionStateMode            mode,
                          bool                        isReadonly)
    {
      pId            = id;   
      pSessionItems  = sessionItems;
      pStaticObjects = staticObjects;
      pTimeout       = timeout;    
      pNewSession    = newSession; 
      pCookieMode    = cookieMode;
      pMode          = mode;
      pIsReadonly    = isReadonly;
    }


    public int Timeout
    {
      get { return pTimeout; }
      set
      {
        if (value <= 0)
          throw new ArgumentException("Timeout value must
 be greater than zero.");

        if (value > MAX_TIMEOUT)
          throw new ArgumentException("Timout cannot be greater
 than " + MAX_TIMEOUT.ToString());

        pTimeout = value;
      }
    }


    public string SessionID
    {
      get { return pId; }
    }


    public bool IsNewSession
    {
      get { return pNewSession; }
    }


    public SessionStateMode Mode
    {
      get { return pMode; }
    }


    public bool IsCookieless
    {
      get { return CookieMode == HttpCookieMode.UseUri;
 }
    }


    public HttpCookieMode CookieMode
    {
      get { return pCookieMode; }
    }


    //
    // Abandon marks the session as abandoned. The IsAbandoned property
 is used by the
    // session state module to perform the abandon work during the ReleaseRequestState
 event.
    //
    public void Abandon()
    {
      pAbandon = true;
    }

    public bool IsAbandoned
    {
      get { return pAbandon; }
    }

    //
    // Session.LCID exists only to support legacy ASP compatibility.
 ASP.NET developers should use
    // Page.LCID instead.
    //
    public int LCID
    {
      get { return Thread.CurrentThread.CurrentCulture.LCID;
 }
      set { Thread.CurrentThread.CurrentCulture = CultureInfo.ReadOnly(new
 CultureInfo(value)); }
    }


    //
    // Session.CodePage exists only to support legacy ASP compatibility.
 ASP.NET developers should use
    // Response.ContentEncoding instead.
    //
    public int CodePage
    {
      get
      { 
        if (HttpContext.Current != null)
          return HttpContext.Current.Response.ContentEncoding.CodePage;
        else
          return Encoding.Default.CodePage;
      }
      set
      { 
        if (HttpContext.Current != null)
          HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding(value);
      }
    }


    public HttpStaticObjectsCollection StaticObjects
    {
      get { return pStaticObjects; }
    }


    public object this[string
 name]
    {
      get { return pSessionItems[name]; }
      set { pSessionItems[name] = value; }
    }


    public object this[int
 index]
    {
      get { return pSessionItems[index]; }
      set { pSessionItems[index] = value; }
    }
        

    public void Add(string
 name, object value)
    {
      pSessionItems[name] = value;        
    }


    public void Remove(string
 name)
    {
      pSessionItems.Remove(name);
    }


    public void RemoveAt(int
 index)
    {
      pSessionItems.RemoveAt(index);
    }


    public void Clear()
    {
      pSessionItems.Clear();
    }

    public void RemoveAll()
    {
        Clear();
    }



    public int Count
    {
      get { return pSessionItems.Count; }
    }



    public NameObjectCollectionBase.KeysCollection Keys
    {
      get { return pSessionItems.Keys; }
    }


    public IEnumerator GetEnumerator()
    {
      return pSessionItems.GetEnumerator();
    }


    public void CopyTo(Array items, int
 index)
    {
      foreach (object o in items)
        items.SetValue(o, index++);
    }


    public object SyncRoot
    {
        get { return this;
 }
    }


    public bool IsReadOnly
    {
      get { return pIsReadonly; }
    }


    public bool IsSynchronized
    {
      get { return false;
 }
    }
  }
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IHttpSessionState プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ CodePage 現在のセッションコード ページ識別子取得または設定します
パブリック プロパティ CookieMode アプリケーションCookie なしのセッション用に構成されているかどうかを示す値を取得します
パブリック プロパティ Count セッション状態項目のコレクション内の項目数取得します
パブリック プロパティ IsCookieless セッション IDURL埋め込むか、HTTP cookie格納するかを示す値を取得します
パブリック プロパティ IsNewSession 現在の要求セッション作成されたかどうかを示す値を取得します
パブリック プロパティ IsReadOnly セッション読み取り専用かどうかを示す値を取得します
パブリック プロパティ IsSynchronized セッション状態値のコレクションへのアクセス同期されている (スレッド セーフである) かどうかを示す値を取得します
パブリック プロパティ Item オーバーロードされます個別セッション状態項目値を取得または設定します
パブリック プロパティ Keys セッション状態項目のコレクション格納されているすべての値のキーコレクション取得します
パブリック プロパティ LCID 現在のセッションロケール識別子 (LCID: locale identifier) を取得または設定します
パブリック プロパティ Mode 現在のセッション状態モード取得します
パブリック プロパティ SessionID セッション一意セッション識別子取得します
パブリック プロパティ StaticObjects ASP.NET アプリケーションの Global.asax ファイル<object Runat="Server" Scope="Session"/> タグ宣言されているオブジェクトコレクション取得します
パブリック プロパティ SyncRoot セッション状態値のコレクションへのアクセス同期使用できるオブジェクト取得します
パブリック プロパティ Timeout セッション状態プロバイダセッション終了するまでの、要求間で許容されるタイムアウト時間 (分単位) を取得または設定します
参照参照

関連項目

IHttpSessionState インターフェイス
System.Web.SessionState 名前空間

その他の技術情報

ASP.NETセッション状態

IHttpSessionState メソッド


IHttpSessionState メンバ

カスタムセッション状態コンテナ実装するコントラクト定義します

IHttpSessionState データ型公開されるメンバを以下の表に示します


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ CodePage 現在のセッションコード ページ識別子取得または設定します
パブリック プロパティ CookieMode アプリケーションCookie なしのセッション用に構成されているかどうかを示す値を取得します
パブリック プロパティ Count セッション状態項目のコレクション内の項目数取得します
パブリック プロパティ IsCookieless セッション IDURL埋め込むか、HTTP cookie格納するかを示す値を取得します
パブリック プロパティ IsNewSession 現在の要求セッション作成されたかどうかを示す値を取得します
パブリック プロパティ IsReadOnly セッション読み取り専用かどうかを示す値を取得します
パブリック プロパティ IsSynchronized セッション状態値のコレクションへのアクセス同期されている (スレッド セーフである) かどうかを示す値を取得します
パブリック プロパティ Item オーバーロードされます個別セッション状態項目値を取得または設定します
パブリック プロパティ Keys セッション状態項目のコレクション格納されているすべての値のキーコレクション取得します
パブリック プロパティ LCID 現在のセッションロケール識別子 (LCID: locale identifier) を取得または設定します
パブリック プロパティ Mode 現在のセッション状態モード取得します
パブリック プロパティ SessionID セッション一意セッション識別子取得します
パブリック プロパティ StaticObjects ASP.NET アプリケーションの Global.asax ファイル<object Runat="Server" Scope="Session"/> タグ宣言されているオブジェクトコレクション取得します
パブリック プロパティ SyncRoot セッション状態値のコレクションへのアクセス同期使用できるオブジェクト取得します
パブリック プロパティ Timeout セッション状態プロバイダセッション終了するまでの、要求間で許容されるタイムアウト時間 (分単位) を取得または設定します
パブリック メソッドパブリック メソッド
参照参照

関連項目

IHttpSessionState インターフェイス
System.Web.SessionState 名前空間

その他の技術情報

ASP.NETセッション状態


このページでは「.NET Framework クラス ライブラリ リファレンス」からIHttpSessionStateを検索した結果を表示しています。
Weblioに収録されているすべての辞書からIHttpSessionStateを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からIHttpSessionState を検索

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

辞書ショートカット

すべての辞書の索引

「IHttpSessionState」の関連用語

IHttpSessionStateのお隣キーワード
検索ランキング

   

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



IHttpSessionStateのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS