servercontroller -> Onclose session call to url

<< Click to Display Table of Contents >>

Navigation:  Forum >

servercontroller -> Onclose session call to url

Forum link

 


 

08-30-2021, 04:42 PM:

 

In the IWServerControllerBaseCloseSession I need to be able to call a url to close a session on an identity server.  (I do not need to redirect the user.   I only need to call the url)

 

Has anyone already done this?

 

Thanks.

 


 

08-31-2021, 11:02 AM:

 

IntraWeb has utility classes to perform this task:

 

Code:

 

implementation

 

{$R *.dfm}

 

uses

 

  IWInit, IWGlobal, IW.Common.Threads, IW.HTTP.IndyClient;

 

{ TIWServerController }

 

procedure TIWServerController.IWServerControllerBaseCloseSession(

 

  aSession: TIWApplication);

 

begin

 

  if Assigned(aSession) then

 

  begin

 

    TIWThreadBase.ExecInThread(

 

      procedure (AThread: TObject)

 

      var

 

        IndyClient: TIWHTTPClient;

 

      begin

 

        IndyClient := TIWHTTPClient.Create;

 

        try

 

          IndyClient.Get('http(s)://yourserver.com/theurl');

 

          // or

 

          // IndyClient.Post('http(s)://yoursever.com/theurl', 'Param1=Value1');&nbsp;&nbsp;// there are 2 other overloads of this

 

        finally

 

          IndyClient.Free;

 

        end;

 

      end,

 

      'Thread_' + aSession.AppID);&nbsp;&nbsp;// <- the name of the thread is just nice to have

 

  end;

 

end;

 

 

 

In this code I use the TIWHttpClient to send a GET or POST request to some arbitrary URL from a Thread (so it won't block the termination of the session - have in mind that connection to a different server, especially using HTTPS, can take a long time).

 

HTTPS connections also require OpenSSL DLLs available in the same directory where your application is.

 


 

09-03-2021, 06:59 PM:

 

Thanks. That looks like it is exactly what we needed.