简体   繁体   中英

Datasnap: Session destroy event

In my application, whenever a user logs in, he is added to a table that stores data about the logged users, but I have nothing implemented to take those users off my table. I need to remove that user from my table when he logs out or loses his session in any other way. Is there a "SessionDestroy" event or something like that, that allows me do implement something upon a destroyed session?

You can add "session events" (using anonymous methods) to the Session Manager. Since 2009, I guess (but tested on XE). Works for REST sessions and more. Sample code:

 TDSSessionManager.Instance.AddSessionEvent(
procedure (Sender: TObject; const EventType: TDSSessionEventType;
  const session: TDSSession)
begin
  case EventType of
    SessionCreate :
    begin
      session.UserRoles.Add('guest'); // guest role is fixed
      ...
    end;
    SessionClose:
    begin
      FreeAndNil(some_more_data);
    end;
  end;
end);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM