|
<< Click to Display Table of Contents >> Navigation: Forum > Close Remote Session |
05-04-2021, 09:41 PM:
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!
05-05-2021, 03:40 AM:
There may be some info here that will help:
https://www.atozed.com/forums/thread-195...ml#pid6743
Dan
05-05-2021, 01:43 PM:
(05-05-2021, 03:40 AM)DanBarclay Wrote: [ -> ]There may be some info here that will help:
https://www.atozed.com/forums/thread-195...ml#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?
05-05-2021, 11:23 PM:
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.
05-06-2021, 11:43 AM:
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;
05-11-2021, 10:45 AM:
(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.
05-11-2021, 10:45 AM:
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;
05-11-2021, 03:06 PM:
(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!