This method creates a new Session record for the current user. New sessions should be created when the session doesn't already exist. The following example demonstrates:

lcID = Request.GetCookie("wwDemoCookie")

loSession = CREATE("wwSession","wwDemoSession")

IF !loSession.IsValidSession(lcID)
   lcID = loSession.NewSession()

   *** Add the cookie to the HTTP header

*** Make sure the cookie gets written

... more HTML here


NewSession() tends to be preceeded by a call to IsValidSession() to determine whether a new session needs to be created for the user. Obviously you have more control about this code such as first going to a login page and then assigning the new session after the user logged in successfully.

Use wwProcess::InitSession()

In most applications you don't have to write code like this - instead wwProcess::InitSession() if called from your wwProcess::OnInitProcess() method will perform this task for you and ensure that the Session object will be precreated for you.

Unless you have a very specific reason for overriding Session behavior we recommend not to do your own session handling. Use InitSession() since it provides the 99% use case without the extra code and logic to ensure that the Session gets properly initialized for each request.


Return Value

String of the new session ID


Optional - a user id to store in the new session.

See also:

Class wwSession

© West Wind Technologies, 1996-2022 • Updated: 02/18/15
Comment or report problem with topic