Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect on session timeout
#1
I have a Isapi intraweb app that when a sesssion timeout occurs i want to terminateAndRedirect to a specific URL not restart the sesssion
I have tried using OnSessionRestarted, but the terminateAndRedirect access violates.

Is there another way to do this?
Reply
#2
One option that comes to mind is to turn on the Form.Keepalive, then set up your own mechanism to time out the session. That will give you an event you can code.

https://www.atozed.com/forums/thread-104...-2948.html

I don't believe there is currently a "BeforeSessionTimeout" event, but that might be worth considering somewhere in the future (@Alex)? It may already be there and I might not have kept up with that.

Dan
Reply
#3
Hi, see this demo:
https://github.com/Atozed/IntraWeb/blob/...roller.pas
Code:
class function TIWExceptionRendererEx.RenderHTML(AException: Exception;
  ARequest: THttpRequest): string;
var
  Addr: string;
begin
  // the goal here is to respond to a session timeout error with a HTML with your address
  if AException is EInvalidSession then begin
    Addr := #39 + 'https://especificURL.com' + #39; // start address enclosed in single quotes
    Result := '<!DOCTYPE html>' +
              '<html>' +
              '<head>' +
              '<script type="text/javascript">' +
              'setTimeout("window.location=' + Addr + '", 1);' +
              '</script>' +
              '</head>' +
              '<body>' +
              '</body>' +
              '</html>';
  end
  else
    Result := inherited;
end;
Reply
#4
Thanks Jose, I didn't remember that being in there. I'll have to give it a try and add it to my cheat sheet.

Dan
Reply
#5
(04-16-2021, 05:59 PM)PDSBILL Wrote: I have a Isapi intraweb app that when a sesssion timeout occurs i want to terminateAndRedirect to a specific URL not restart the sesssion
I have tried using OnSessionRestarted, but the terminateAndRedirect access violates.

Is there another way to do this?


OnSessionRestarted occurs after a new session is created in response to a new request, meaning that you can't actually handle a session timeout from there. If 

A better way to handle this is handling the exception using the example that JNP posted above
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)