HttpSessionStateContainer Constructor (String, ISessionStateItemCollection, HttpStaticObjectsCollection, Int32, Boolean, HttpCookieMode, SessionStateMode, Boolean)
Creates a new HttpSessionStateContainer object and initializes it with the specified settings and values.
Assembly: System.Web (in System.Web.dll)
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 )
Parameters
- id
-
Type:
System.String
A session identifier for the new session. If null, an ArgumentException is thrown.
- sessionItems
-
Type:
System.Web.SessionState.ISessionStateItemCollection
An ISessionStateItemCollection that contains the session values for the new session-state provider.
- staticObjects
-
Type:
System.Web.HttpStaticObjectsCollection
An HttpStaticObjectsCollection that specifies the objects declared by <object Runat="Server" Scope="Session"/> tags within the ASP.NET application file Global.asax.
- timeout
-
Type:
System.Int32
The amount of time, in minutes, allowed between requests before the session-state provider terminates the session.
- newSession
-
Type:
System.Boolean
true to indicate the session was created with the current request; otherwise, false.
- cookieMode
-
Type:
System.Web.HttpCookieMode
The CookieMode for the new session-state provider.
- mode
-
Type:
System.Web.SessionState.SessionStateMode
One of the SessionStateMode values that specifies the current session-state mode.
- isReadonly
-
Type:
System.Boolean
true to indicate the session is read-only; otherwise, false.
| Exception | Condition |
|---|---|
| ArgumentNullException | id is null. |
The following code example shows the AcquireRequestState event handler for a custom session-state module that populates a new HttpSessionStateContainer object with new or existing session information and adds it to the HttpContext of the current request using the AddHttpSessionStateToContext method. For a full code example of a custom session-state module, see the SessionStateUtility class overview.
'
' 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
Available since 2.0