IHttpSessionState 인터페이스

정의

사용자 지정 세션 상태 컨테이너를 구현하기 위한 계약을 정의합니다.

public interface class IHttpSessionState
public interface IHttpSessionState
type IHttpSessionState = interface
Public Interface IHttpSessionState
파생

예제

다음 코드 예제에서는 구현 된 IHttpSessionState 라는 새 세션 상태 컨테이너 클래스를 만들려면 인터페이스 MySessionState합니다.

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; }
    }
  }
}
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

설명

세션 상태 컨테이너 세션 상태 값 및 현재 세션에 대 한 관련된 정보에 액세스할 수 있습니다. 세션 상태 컨테이너에 포함 된 세션 정보를 통해 애플리케이션 코드에 노출 되는 HttpSessionState 를 사용 하 여 클래스를 Session 속성입니다. HttpSessionState 클래스는 세션 상태 컨테이너에 대 한 래퍼 클래스입니다.

세션 상태 컨테이너의 ASP.NET 구현은 HttpSessionStateContainer 클래스입니다. 요청의 시작 부분에 중 합니다 AcquireRequestState 이벤트를 SessionStateModule 를 만들고 채웁니다는 HttpSessionStateContainer 개체와 현재 할당 HttpContext. 요청의 끝 중를 ReleaseRequestState 이벤트를 SessionStateModule 검색 합니다 HttpSessionStateContainer 현재에서 개체 HttpContext 세션 저장소에 세션 값을 기록 하거나 중단 등 모든 필요한 세션 작업을 수행 하 고는 세션입니다. 요청 종료 되는 경우 갑자기, 등을 리디렉션을 통해는 SessionStateModule 호출 하 여 동일한 정리를 수행 합니다 EndRequest 메서드.

컨테이너를 만들려면 사용자 지정 세션 상태를 구현 하는 클래스를 만들기는 IHttpSessionState 인터페이스입니다. 사용자 고유의 사용자 지정 세션 상태 컨테이너를 만드는 경우 바꾸는 작업도 수행 해야 합니다 SessionStateModule 사용자 고유의 사용자 지정 모듈을 사용 하 여 합니다. 사용자 지정 모듈을 사용자 지정 세션 상태 컨테이너의 인스턴스를 만들고 현재 추가 HttpContext 를 사용 하 여 AddHttpSessionStateToContext 메서드. 에 포함 된 사용자 지정 세션 상태 모듈의 예로 SessionStateUtility 클래스 개요.

속성

CodePage

현재 세션에 대한 코드 페이지 식별자를 가져오거나 설정합니다.

CookieMode

애플리케이션에서 쿠키 없는 세션을 구성할지 여부를 나타내는 값을 가져옵니다.

Count

세션 상태 항목 컬렉션의 항목 수를 가져옵니다.

IsCookieless

세션 ID가 URL에 포함되어 있는지 HTTP 쿠키에 저장되어 있는지 여부를 나타내는 값을 가져옵니다.

IsNewSession

세션을 현재 요청으로 만들었는지 여부를 나타내는 값을 가져옵니다.

IsReadOnly

세션이 읽기 전용인지 여부를 나타내는 값을 가져옵니다.

IsSynchronized

세션 상태 값의 컬렉션에 대한 액세스가 동기화(스레드로부터 안전)되는지 여부를 나타내는 값을 가져옵니다.

Item[Int32]

숫자 인덱스별로 세션 상태 항목 값을 가져오거나 설정합니다.

Item[String]

이름별로 세션 상태 항목 값을 가져오거나 설정합니다.

Keys

세션 상태 항목 컬렉션에 저장된 모든 값의 키 컬렉션을 가져옵니다.

LCID

현재 세션의 LCID(로캘 식별자)를 가져오거나 설정합니다.

Mode

현재 세션 상태 모드를 가져옵니다.

SessionID

세션의 고유한 세션 식별자를 가져옵니다.

StaticObjects

ASP.NET 애플리케이션 파일 Global.asax에서 <object Runat="Server" Scope="Session"/> 태그로 선언된 개체 컬렉션을 가져옵니다.

SyncRoot

세션 상태 값의 컬렉션에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

Timeout

세션 상태 공급자가 세션을 종료하기 전의 요청 사이에 허용되는 시간 제한(분)을 가져오거나 설정합니다.

메서드

Abandon()

현재 세션을 종료합니다.

Add(String, Object)

세션 상태 컬렉션에 새 항목을 추가합니다.

Clear()

세션 상태 항목 컬렉션에서 모든 값을 지웁니다.

CopyTo(Array, Int32)

배열의 지정된 인덱스에서 시작하여 세션 상태 항목 값의 컬렉션을 1차원 배열에 복사합니다.

GetEnumerator()

현재 세션에서 모든 세션 상태 항목 값을 읽는 데 사용할 수 있는 열거자를 반환합니다.

Remove(String)

세션 상태 항목 컬렉션에서 항목을 삭제합니다.

RemoveAll()

세션 상태 항목 컬렉션에서 모든 값을 지웁니다.

RemoveAt(Int32)

세션 상태 항목 컬렉션에서 지정된 인덱스의 항목을 삭제합니다.

적용 대상

추가 정보