Jump to content

Сlosure of the session


Volk65

Recommended Posts

Hi!

I need to track the closing/termination of the session. As I understand the session can be closed:

1) timeout

2) if the user closed the browser

3) if the "Close;" in the main window

4) other...

Where better to catch the event "Session closed" (before closing the session) to record information in the database?

Link to comment
Share on other sites

  • 2 years later...

Hello!! 

I made a function to not permit the same user login in two different PCs, so when i detect that same user in another PC i want to kill the old session. 

Here is the question: How can i kill the session manually, without use "timeout"?

 

I searched in another topics for this and did not find the answer.

Link to comment
Share on other sites

9 minutes ago, freedowsRoO said:

Here is the question: How can i kill the session manually, without use "timeout"?

Hello,

You can also analyze this demo example I think:

\FMSoft\Framework\uniGUI\Demos\Desktop\Session List

 

  • Like 1
Link to comment
Share on other sites

2 minutes ago, Sherzod said:

Hello,

You can also analyze this demo example I think:


\FMSoft\Framework\uniGUI\Demos\Desktop\Session List

 

I'm already looked at this demo, this demo show how to get the sessions not how kill them.

 i'm already use the demo example to save the sessions im my DB.

Link to comment
Share on other sites

2 minutes ago, freedowsRoO said:

this demo show how to get the sessions not how kill them.

procedure TMainForm.UniButton2Click(Sender: TObject);
var
  SId : string;
  SS : TUniGUISession;
begin
  SId := ClientDataSet1.FieldByName('sessionid').AsString;
  if (SId <> '') and (SId <> UniSession.SessionId) then
  begin
    SS := UniServerModule.GetSession(SId);
    if Assigned(SS) then
      try
        SS.TerminateAfterSecs(1);
      finally
        SS.UnBusy;
      end;
  end;
end;

 

  • Like 2
Link to comment
Share on other sites

This is what I do on Server Shut Down (UniGUIServerModuleBeforeShutdown), modify my code and use elsewhere by filtering the SessionID in question.

Remember that Browsers still open (UniGUIMainModuleSessionTimeout) will force the Server to try and reconnect, so after running my code below on shutdown and subsequent restart you will still get:-

"EUniSessionException : Invalid session or session Timeout. (Session not found: ..." error messages in the Server Log until the Browser is closed -or- the session in question is let go of by the Browser.  

 

procedure TUniServerModule.UniGUIServerModuleBeforeShutdown(Sender: TObject);
var
  I, p: Integer;
  S: TUniGUISessions;
  U: TUniGUISession;
begin
  S:= UniServerModule.SessionManager.Sessions;
  S.Lock;
  try
    for I:= 0 to S.SessionList.Count - 1 do begin
      U:= S.SessionList;
      if U.UniMainModule <> nil then begin
        try
          U.ReleaseSession;
          U.Terminate('Closed !');
        except
        end;
      end; // nil
    end; // for
  except
  end;
  S.Unlock;
end;
 

procedure TUniMainModule.UniGUIMainModuleSessionTimeout(ASession: TObject; var ExtendTimeOut: Integer);
var
  Cmp: TComponent;
  s, s0, s1, s2: String;
begin
  Inc(SessionMinutesCounter);
  if UniMainModule.TracePulse = True then begin 
    s:= 'http';
    if SecureFlag = True then begin
      s:= 'HTTPS';
    end;
    DateTimeToString(formattedDateTime, 'dd/mm/yyyy hh:nn:ss.z', Now());
    s0:= formattedDateTime;
    if EditedBy <> '' then begin
      s0:= EditedBy + ' ' + formattedDateTime;
    end;
    //////////////////////////////////////////////////////////////////////////////
    try
      Cmp:= TUniGUIApplication(UniApplication).UniSession.CurrentComponent;
      if Assigned(Cmp) then begin
        s1:= Cmp.Name + ' (' + Cmp.ClassName + ')';
        if Cmp is TUniControl then s2:= TUniControl(Cmp).OwnerForm.Name
        else if Cmp is TUniComponent then s2:= TUniComponent(Cmp).OwnerForm.Name
        else s2:= '';
        uniServerModule.Logger.AddLog('ANDY-M', s+' "Session.TimeOut ('+s0+', '+IntToStr(SessionMinutesCounter)+' mins, SessionID:' + SessionIDstr + ', ' + UniMainModule.EditedBy + ', Component ' + s1 + ', Extended 3mins)"');
      end else begin
        uniServerModule.Logger.AddLog('ANDY-M', s+' "Session.TimeOut ('+s0+', '+IntToStr(SessionMinutesCounter)+' mins, SessionID:' + SessionIDstr + ', ' + UniMainModule.EditedBy + ', Extended 3mins)"');
      end;
    except
    end;
  end; // TracePulse
  //////////////////////////////////////////////////////////////////////////////
  ExtendTimeOut:= (1000 * 180); // 3mins
end;

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
On 1/9/2020 at 5:15 PM, Sherzod said:

procedure TMainForm.UniButton2Click(Sender: TObject);
var
  SId : string;
  SS : TUniGUISession;
begin
  SId := ClientDataSet1.FieldByName('sessionid').AsString;
  if (SId <> '') and (SId <> UniSession.SessionId) then
  begin
    SS := UniServerModule.GetSession(SId);
    if Assigned(SS) then
      try
        SS.TerminateAfterSecs(1);
      finally
        SS.UnBusy;
      end;
  end;
end;

 

This code doesn't work with HyperServer, what do you need to adapt to make it work?

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...