Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi XE2 Datasnap Session Management - get session information after page reload

I am trying to determine how to retrieve session information using a Delphi REST DataSnap server.

I know that, when on the same client page, you have access to the current thread session using the TDSSession method GetThreadSession.

What I want to do, however, is store data in the session (putData) and still be able to retrieve it when the user moves from page1 to page2. At present, if the user moves to a different page, the session is lost and a new one is created, thus loosing the data in the session that I had previously set.

I have tried playing with TDSSessionManager.SetThreadSession(sessionid) - but I cant seem to get it working.

I've reviewed the much acclaimed Marco Cantu white paper, however, it doesn't provide a solution to this issue.

Any help I can get on this would be great - even if its just 'hey, this topic is covered in book X'.

Thanks!

like image 388
ConBran Avatar asked Jul 09 '12 13:07

ConBran


2 Answers

The TDSSessionManager.SetThreadSession(sessionid) works with Session.sessionname.

Plus make sure your Lifecycle is set to Session (as stated by tondrej).

If you reconnect your client. a new session is started. So you want to keep your Datasnap connection open.

Or you can set the lifecycle to Server and mannage the client-sessions yourself.

Edit: Rest Servers are Stateless. So you need to store the page you are on on the Client. And Query the needed Page from the Server

like image 67
r_j Avatar answered Nov 05 '22 09:11

r_j


You have to tweak the client side JavaScript to use a cookie to store session info.

See the last part of JavaScript Client Sessions

If you want to keep server side objects active for the session use the Session life cycle.

like image 1
Miguel Angel Suarez Rodriguez Avatar answered Nov 05 '22 08:11

Miguel Angel Suarez Rodriguez