Session
Session : 4D.Session
| Parameter | Type | Description | |
|---|---|---|---|
| Function result | 4D.Session | ← | Session object |
History
| Release | Changes |
|---|---|
| 21 R3 | Support of remote sessions on the client machine |
| 20 R8 | Support of standalone sessions |
| 20 R5 | Support of remote client and stored procedure sessions |
| 18 R6 | Added |
Description
The Session command returns the Session object corresponding to the current session.
Depending on the process from which the command is called, the current session can be:
- a web session (when scalable sessions are enabled),
- a remote user session (on the server or on the client),
- a stored procedures session,
- a standalone session.
For more information, see the Session types paragraph.
The command returns Null if it is called in a web process and scalable sessions are disabled on the web server.
Web sessions
The Session object of web sessions is available from any web process:
On Web Authentication,On Web Connection, andOn REST Authenticationdatabase methods,- code processed through 4D tags in semi-dynamic pages (4DTEXT, 4DHTML, 4DEVAL, 4DSCRIPT/, 4DCODE)
- project methods with the "Available through 4D tags and URLs (4DACTION...)" attribute and called through 4DACTION/ urls,
On Mobile App AuthenticationandOn Mobile App Actiondatabase methods for mobile requests,- ORDA functions called with REST requests.
Remote user sessions
The remote user session object is available on the server and on the client. Both objects are similar, except that they don't share the same session.storage property and the client session cannot set privileges (see this paragraph for more information).
The Session object of a remote user session is available:
- On the server, from code running in the user context, such as project methods that have the Execute on Server attribute (they are executed in the "twinned" process of the client process) or ORDA data model functions.
- On the client, from code running locally, such as in project methods or ORDA data model functions with the local property.
For more information, see the "Availability" paragraph.
Stored procedures session
All stored procedure processes share the same virtual user session. The Session object of stored procedures is available from:
- methods called with the
Execute on servercommand, On Server Startup,On Server Shutdown,On Backup Startup,On Backup Shutdown, andOn System eventdatabase methods
For more information on stored procedures virtual user session, please refer to the Stored procedure sessions paragraph.
Standalone session
The Session object is available from any process in standalone (single-user) applications so that you can write and test your client/server code using the Session object in your 4D development environment.
For more information on standalone sessions, please refer to the Standalone sessions paragraph.
Session and components
When Session is called from the code of different components loaded in the project, the command returns an object depending on the calling request and the context:
- in case of a web request,
Sessionalways returns the session attached to the target web server of the request (and not a session of the component's web server), - in case of a remote request executed on the server,
Sessionalways returns the session attached to the remote user, - in case of a stored procedure session or a standalone session,
Sessionalways returns the single current session (the same object is used during all the work session).
Example
You have defined the action_Session method with attribute "Available through 4D tags and URLs". You call the method by entering the following URL in your browser:
IP:port/4DACTION/action_Session
//action_Session method
Case of
:(Session#Null)
If(Session.hasPrivilege("CreateInvoices")) //calling the hasPrivilege function
WEB SEND TEXT("4DACTION --> Session is CreateInvoices")
Else
WEB SEND TEXT("4DACTION --> Session is not CreateInvoices")
End if
Else
WEB SEND TEXT("4DACTION --> Session is null")
End case
See also
Session storage
Session API
Desktop sessions
Web server user sessions
Scalable sessions for advanced web applications (blog post)
4D remote session object with Client/Server connection and Stored procedure
Client / server – Handle a session when working on a 4D client
Properties
| Command number | 1714 |
| Thread safe | yes |