How to Warn Users Before Their Session Times Out in Oracle APEX

Set the idle time and the timeout warning, see the Extend dialog and the end-of-session dialog, and test that Extend keeps the session alive.

An APEX session ends after a period of inactivity, set by the application's idle time. A user who fills in a long form, takes a phone call, and then clicks Save can lose the work, because the session ended while the page was open. Oracle APEX can warn users before that happens: a dialog shows when the session will end and offers to extend it with one click. This is a setting, not code. This guide sets it up, shows the warning and the end-of-session dialog, and checks that extending really keeps the session alive.

Step 1: Set the Idle Time and the Warning

In App Builder, open Shared Components, then Security Attributes, and go to Session Management:

  • Maximum Session Idle Time in Seconds: how long a session may be inactive before it ends.
  • Session Timeout Warning in Seconds: how many seconds before the end the warning appears.
Oracle APEX Security Attributes, Session Management section, with Maximum Session Idle Time 120 seconds and Session Timeout Warning 60 seconds
The test values: idle time 120 seconds, warning 60 seconds before the end.

The values here are short so the behavior can be tested in two minutes. In a real application, typical values are an idle time of 1800 to 3600 seconds and a warning of 120 to 300 seconds. When the idle time is empty, the workspace or instance value applies.

The settings can be checked with a query:

Example:

select maximum_session_life_seconds as max_length,
       maximum_session_idle_seconds as max_idle,
       session_timeout_warn_seconds as warn_before
from   apex_applications
where  application_id = 400;

Output:

   MAX_LENGTH    MAX_IDLE    WARN_BEFORE
_____________ ___________ ______________
                      120             60

Step 2: What the User Sees

A user, SALES_USER, opens the Sales Dashboard and leaves it alone. After 60 seconds without activity, 60 seconds before the end, the warning appears with the time at which the session will end:

Oracle APEX dialog Your session will end at 14:06:22. Would you like to extend it? with Cancel and Extend buttons over the Sales Dashboard
The warning, shown in the browser while the page is open.

Extend sends a request to the server, which counts as activity, so the idle time starts again. Cancel closes the dialog and leaves the session to end. If the user does nothing, the session ends at the time shown, and the dialog changes:

Oracle APEX dialog Your session has ended with Cancel and Sign In Again buttons
After the idle time: the session has ended.

Sign In Again goes to the login page. The page that was open is not submitted, so unsaved values on it are lost; the warning is what gives the user the chance to avoid that.

Testing the Extend Button

In a test, the warning appeared 56 seconds after the page loaded, and Extend was clicked. At 136 seconds, past the original end of the session at 120 seconds, the session was still alive: reloading the page showed the dashboard, not the login page. Because the page was idle again after the click, a new warning had appeared, with a new end time.

Things to Know

  • Activity means requests to the server: page loads, submits, and Ajax calls such as a refreshing region. Typing in a form without submitting it is not activity, which is why long forms need the warning.
  • Maximum Session Length in Seconds limits the total length of a session, however active it is. Extend cannot go beyond it.
  • Session Idle Timeout URL and Session Timeout URL send the user to a page of your choice instead of the default login page, for example a page that explains why the session ended.
  • The settings are per application. Workspace and instance administrators can set defaults for applications that leave them empty.

Related Guides

Conclusion

To warn Oracle APEX users before their session times out, set Maximum Session Idle Time and Session Timeout Warning in Security Attributes. APEX then shows a dialog with the end time and an Extend button, which restarts the idle time, and a Sign In Again dialog when the session has ended. No JavaScript is needed.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted