Name
IsNewSession
Synopsis
Boolean = Session.IsNewSession
Returns a Boolean indicating whether the current session was created as a result of the current request.
Parameters
-
Boolean A Boolean variable that will receive the IsNewSession property value. Returns
Trueon the request that creates a Session andFalsefor each subsequent request from the same client.
Example
The example tests to see if the current request created a new session and if so, adds a value to the Session collection and then displays a message containing the SessionID of the current session:
Sub Page_Load( )
If Session.IsNewSession Then
Session("foo") = "foo"
Message.Text = "The current Session (SessionID: " & _
Session.SessionID & ") was created with this request."
Else
Message.Text = "The current Session (SessionID: " & _
Session.SessionID & ") existed prior to this request."
End If
End SubNotes
The IsNewSession property is very useful when you want to initialize
Session collection items for only certain pages. Unlike the
Session_OnStart event handler in global.asax,
which is called when a session is created, regardless of which page
creates the session, this property gives you finer-grained control
over initialization and session behavior.
As mentioned in the introduction to this chapter, while a new SessionID is generated for each request that does not already have a session, a new session is not created for a given request unless the requested page stores a value in the Session collection or an event handler ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access