다음을 통해 공유


HttpSessionStateContainer 생성자

정의

HttpSessionStateContainer 개체를 만들고 지정된 설정과 값으로 초기화합니다.

public:
 HttpSessionStateContainer(System::String ^ id, System::Web::SessionState::ISessionStateItemCollection ^ sessionItems, System::Web::HttpStaticObjectsCollection ^ staticObjects, int timeout, bool newSession, System::Web::HttpCookieMode cookieMode, System::Web::SessionState::SessionStateMode mode, bool isReadonly);
public HttpSessionStateContainer (string id, System.Web.SessionState.ISessionStateItemCollection sessionItems, System.Web.HttpStaticObjectsCollection staticObjects, int timeout, bool newSession, System.Web.HttpCookieMode cookieMode, System.Web.SessionState.SessionStateMode mode, bool isReadonly);
new System.Web.SessionState.HttpSessionStateContainer : string * System.Web.SessionState.ISessionStateItemCollection * System.Web.HttpStaticObjectsCollection * int * bool * System.Web.HttpCookieMode * System.Web.SessionState.SessionStateMode * bool -> System.Web.SessionState.HttpSessionStateContainer
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)

매개 변수

id
String

새 세션의 세션 식별자입니다. null이면 ArgumentException이 throw됩니다.

sessionItems
ISessionStateItemCollection

새 세션 상태 공급자의 세션 값이 포함된 ISessionStateItemCollection입니다.

staticObjects
HttpStaticObjectsCollection

ASP.NET 애플리케이션 파일 Global.asax에서 <object Runat="Server" Scope="Session"/> 태그로 선언된 개체를 지정하는 HttpStaticObjectsCollection입니다.

timeout
Int32

세션 상태 공급자가 세션을 종료하기 전에 요청 사이에 허용되는 시간(분)입니다.

newSession
Boolean

세션을 현재 요청으로 만들었음을 나타내면 true이고, 그렇지 않으면 false입니다.

cookieMode
HttpCookieMode

새 세션 상태 공급자의 CookieMode입니다.

mode
SessionStateMode

현재 세션 상태 모드를 지정하는 SessionStateMode 값 중 하나입니다.

isReadonly
Boolean

세션이 읽기 전용임을 나타내면 true이고, 그렇지 않으면 false입니다.

예외

id이(가) null인 경우

예제

다음 코드 예제는 AcquireRequestState 채우는 새 사용자 지정 세션 상태 모듈에 대 한 이벤트 처리기 HttpSessionStateContainer 신규 또는 기존 세션 정보를 사용 하 여 개체에 추가 합니다는 HttpContext 를사용하여현재요청의AddHttpSessionStateToContext메서드. 사용자 지정 세션 상태 모듈의 전체 코드 예제를 참조 하세요.를 SessionStateUtility 클래스 개요입니다.

//
// 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

적용 대상

추가 정보