Atozed Forums
Close Remote Session - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: Close Remote Session (/thread-2391.html)



Close Remote Session - Rolphy Reyes - 05-04-2021

Hi!

Every time an user make loggin in the application, the AppId (sessionId) is save in the database.

With this information, I try to terminate the session from another program and my code fail every time.

How can I end the session?

Delphi Seattle
Intraweb 15.2.10

Code:
procedure TFrmSesionUsuario.CerrarSesion(const AAppId: string);
var
  lApp: TIWApplication;
  lExpired, lLocked: Boolean;
  I: Integer;
  lForm: TIWAppForm;
begin
  lApp := gSessions.LookupAndLock(AAppId, lExpired, lLocked);
  if Assigned(lApp) and not lExpired then
  begin
    try
      for I := lApp.ActiveFormCount -1 downto 0 do
      begin       
          lForm := TIWAppForm(lApp.ActiveForms[I]);
          lForm.Release;
      end;
      lApp.SessionTimeOut := 1;
      lApp.Terminate;
    finally
      lApp.Unlock;
    end;
  end;
end;


The lApp variable is always NIL.

How can I overcome this problem?

TIA!


RE: Close Remote Session - DanBarclay - 05-05-2021

There may be some info here that will help:

https://www.atozed.com/forums/thread-1950-post-6743.html#pid6743

Dan


RE: Close Remote Session - Rolphy Reyes - 05-05-2021

(05-05-2021, 03:40 AM)DanBarclay Wrote: There may be some info here that will help:

  https://www.atozed.com/forums/thread-1950-post-6743.html#pid6743

Dan

Hi DanBarclay.

Thanks for taking the time to respond.

But if you look carefully enough, that's the same code I used. The thing is that code only works if the AppId (SessionId) is in the same context of that UserSession or Application I would say.

What I'm trying to achieve is that with the AppId store in the database I could terminate ANY session of my applications from another application.

What I want to build is a session manager, so I could control per session how many users entered the system and then be able to release those sessions (terminate the applications) from the same manager.

Is that clear enough?


RE: Close Remote Session - Alexandre Machado - 05-05-2021

Hi,

I'll test your code snippet. One thing that I can tell you that won't ever work is terminating the same session that is being used to execute that code.

Also, any other session currently locked (i.e. responding to any user requests) can't be terminated, until it can be locked.


RE: Close Remote Session - Jose Nilton Pace - 05-06-2021

Hi, try this code:
Code:
procedure TFrmSesionUsuario.CerrarSesion(const AAppId: string);
var
  lApp: TIWApplication;
  I: Integer;
  xList: TList;
  foundit : boolean;
begin
  foundit := false;

  xList := GSessions.LockList(False);
  try
     for i := 0 to xList.Count - 1 do
     begin
        lApp := TIWApplication(xList[i]);
        if lApp.AppID = AAppId then
           begin
              foundit := true;
              break;
           end;
     end;
  finally
     GSessions.UnLockList(xList);
     if (foundit = true) then
        begin
           lApp.Terminate;
        end;
  end;
end;



RE: Close Remote Session - Alexandre Machado - 05-11-2021

(05-06-2021, 11:43 AM)Jose Nilton Pace Wrote: Hi, try this code:
Code:
procedure TFrmSesionUsuario.CerrarSesion(const AAppId: string);
var
  lApp: TIWApplication;
  I: Integer;
  xList: TList;
  foundit : boolean;
begin
  foundit := false;

  xList := GSessions.LockList(False);
  try
     for i := 0 to xList.Count - 1 do
     begin
        lApp := TIWApplication(xList[i]);
        if lApp.AppID = AAppId then
           begin
              foundit := true;
              break;
           end;
     end;
  finally
     GSessions.UnLockList(xList);
     if (foundit = true) then
        begin
           lApp.Terminate;
        end;
  end;
end;

This code should not be used anymore (at least not in IW 15.1 and later). It simply won't complile.


RE: Close Remote Session - Alexandre Machado - 05-11-2021

This code works correctly, as expected.
It terminates locks and terminates the session.

I believe that your problem is that you are trying to lock (and terminate) the same session that is running the command and that, by design, is not allowed. You can terminate all other sessions, except your own session, using this code.
To terminate your own session you must explicitly call IWApplication.Terminate, as usual.

Another point is that you don't need (nor should) release the application forms. The Session itself takes care of all forms when it is being released.

Code:

Code:
procedure TIWForm1.TerminateSession(const AAppId: string);
var
  lApp: TIWApplication;
  lExpired, lLocked: Boolean;
begin
  lApp := gSessions.LookupAndLock(AAppId, lExpired, lLocked);
  if Assigned(lApp) and not lExpired then
  begin
    try
      lApp.Terminate;
    finally
      lApp.Unlock;
    end;
  end;
end;



RE: Close Remote Session - Rolphy Reyes - 05-11-2021

(05-11-2021, 10:45 AM)Alexandre Machado Wrote: This code works correctly, as expected.
It terminates locks and terminates the session.

I believe that your problem is that you are trying to lock (and terminate) the same session that is running the command and that, by design, is not allowed. You can terminate all other sessions, except your own session, using this code.
To terminate your own session you must explicitly call IWApplication.Terminate, as usual.

Another point is that you don't need (nor should) release the application forms. The Session itself takes care of all forms when it is being released.

Code:

Code:
procedure TIWForm1.TerminateSession(const AAppId: string);
var
  lApp: TIWApplication;
  lExpired, lLocked: Boolean;
begin
  lApp := gSessions.LookupAndLock(AAppId, lExpired, lLocked);
  if Assigned(lApp) and not lExpired then
  begin
    try
      lApp.Terminate;
    finally
      lApp.Unlock;
    end;
  end;
end;

Hi!

I will try it and let you know the results. Thanks!