
408
|
Chapter 19: The HttpSessionState Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
create absolute URLs containing the current SessionID for use with cookieless
sessions.
IsNewSession
Boolean = Session.IsNewSession
Returns a Boolean indicating whether the current session was created as a result
of the current request.
Parameter
Boolean
A Boolean variable that will receive the IsNewSession property value. Returns
True on the request that creates a Session and False for 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 Sub
Notes
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 ...