Click or drag to resize


Every user in Wisej is a session and every session corresponds to a single user. You can control the session timeout period, detect when a session is about to expire, store any object in a session and terminate a session programmatically.

What you cannot do is store the session anywhere else other than in memory. Wisej sessions cannot be serialized into a string and saved into a database or a file system. However, you can save and restore any other object in your application from a shared file system, a database, or remote storage.

Using the Session Object

Wisej provides a dynamic Application.Session object that you can use to store and retrieve any object instance in relation to the user session:

Store and Retrieve Session Objects
// Check if an object exists and store it.
if (Application.Session.myStringValue == null)
  Application.Session.myStringValue = "Hello, I'm a session variable";

// You can store any type of object:
Application.Session.someNumericValue = 13;
Application.Session.someDateValue = DateTime.Now();

// You can also retrieve the Session object once and/or pass it around.
dynamic session = Application.Session;
session.WhateverList = new List<Whatever)();

// When retrieving a value, there is no need to cast.
int i = Application.Session.someNumericValue;
Caution note Caution

When retrieving values (int, date, etc.) rather than references from the session object, check for null or you may get an invalid cast exception since nulls cannot cast to values.

Session Timeout

The session timeout determines how long Wisej will wait before terminating an inactive session. The default timeout is 120 seconds (2 minutes) but you can change it in the application's Default.json settings.

Wisej handles session timeouts in two phases, the first is the timeout and the second is the expiration. Expired session are simply removed from memory and all the associated objects are disposed and removed.

There are two reasons for a session to timeout:

  • User Inactivity

    When the user goes to the water cooler or out to lunch - or is simply staring at the screen, for more than the timeout value (which is the value specified in Default.json or the default), Wisej fires the Application.SessionTimeout event allowing your application to react accordingly.

    Unless you handle the Application.SessionTimeout event, Wisej displays a system dialog on the user's browser showing a 2 minute countdown. After 2 minutes, absent any reaction from the user, Wisej terminates the session. There are no events fired when the session is terminated since it's an unrecoverable event.

    Important note Important

    Your application's last chance to handle a session timeout is the Application.SessionTimeout event.

  • User Shutdown

    When the user closes the browser, or shuts down the computer, or loses power, or loses the connection, the result for Wisej is the same: it stops receiving keep-alive messages from the client. When that happens, the session expiration timer starts to tick and after the specified timeout (which is the value specified in Default.json or the default) times 2, Wisej drops the session and disposes all the associated object.

    Any event from the client associated with the session will resume the session and reset the timer. A temporary loss of connection or power can be restored. Tuening the computer back on half an hour later cannot.

Session Expiration

An "abandoned" session expires after twice the sessionTimeout value (in seconds) specified in Default.json or the default 120 second value.

All the windows (pages, forms, ...) in the application are closed and disposed. The CloseReason is CloseReason.ApplicationExit. All the child controls are also disposed firing the Disposed event. If there other objects that are referenced but are not children, they will also be disposed when the GC and their finalizer kicks in.

Caution note Caution

Session expirations are not recoverable.

See Also

Other Resources