03-09-2023, 01:01 PM
This code redirects the user to SessionTimeout.html when the session timeout occurs.
Be sure to register the mimetype .html as static because it is served without session validation.
Be sure to register the mimetype .html as static because it is served without session validation.
Code:
procedure TIWServerController.IWServerControllerBaseConfig(Sender: TObject);
begin
// register my own exception handler
IWExceptionRenderer.SetExceptionRendererClass(TIWExceptionRendererEx);
// register mimetype .html without session validation
TIWMimeTypes.RegisterType('.html', 'text/html', True);
end;
{ TIWExceptionRendererEx }
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 which
// will restart a new session
if AException is EExpiredSession then begin
Addr := #39 + '/SessionTimeout.html' + #39; // wwwroot/SessionTimeout.html
Result := '<!DOCTYPE html>' +
'<html>' +
'<head>' +
'<script type="text/javascript">' +
'setTimeout("window.location=' + Addr + '", 1);' +
'</script>' +
'</head>' +
'<body>' +
'</body>' +
'</html>';
end
else
Result := inherited;
end;
