|
<< Click to Display Table of Contents >> Navigation: Forum > Redirect on session timeout |
04-16-2021, 05:59 PM:
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?
04-16-2021, 09:10 PM:
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
04-16-2021, 10:36 PM:
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;
04-17-2021, 03:14 AM:
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
04-23-2021, 07:33 PM:
(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