Jump to content

How is possible to redirect mobile users to another url?


Tokay

Recommended Posts

On 9/15/2021 at 5:50 PM, Tokay said:

user connected to the 127.0.0.1:8087 from mobile automatically redirects to the 127.0.0.1:8080 (this is not Unigui url).

Hello, try this:

const 

    RedirectURL : string = MyURLtoRedirect;

 

procedure TUniMainModule.UniGUIMainModuleHandleRequest(ASession: TObject;
  var Handled: Boolean);

var   sRefererValues    : TStringList;

begin

    if (UniSession.ARequest.URI = '/HandleEvent')
    AND (TRIM (RedirectURL) <> '')
    AND (UniSession.ARequest.Referer <> RedirectURL)
    then begin
        try
            sRefererValues := TStringList.Create;
            sRefererValues.Delimiter := '&';
            sRefererValues.StrictDelimiter := True;
            sRefererValues.DelimitedText := Copy (UniSession.ARequest.Referer,POS ('/?',UniSession.ARequest.Referer)+1,Length (s));
           //replace url

            RedirectURL := StringReplace (RedirectURL,'[URL]',Copy (TUniGUISession(ASession).URL,1,POS (':',TUniGUISession(ASession).URL)) + '/',[rfReplaceAll]);

           //copy other parameters

            RedirectURL := StringReplace (RedirectURL,'[lgn]',sRefererValues.Values['lgn'],[rfReplaceAll]);
        finally
            sRefererValues.Clear;
            FreeAndNil (sRefererValues);
        end;

        //redirect 
        UniSession.AResponse.ResponseNo := 308;
        UniSession.AResponse.ResponseText := 'redirected';
        UniSession.TerminateAfterSecs(2);

        UniSession.UrlRedirect (RedirectURL);        
    end;
end;

end;

 

This can be used to redirect from http:// to https:// at startup of session

Link to comment
Share on other sites

Thank you. I've try your method. Redirect works, but the desctop login form shows for 2-3 seconds. Maybe someone know how to fix this?

var
 RedirectURL: string;
begin
 if upMobile in UniSession.UniPlatform then
 begin
  RedirectURL := WebDataModule.SiteRoot;
  if (UniSession.ARequest.URI = '/HandleEvent') and (TRIM(RedirectURL) <> '') and
   (UniSession.ARequest.Referer <> RedirectURL) then
  begin
   //redirect
   UniSession.AResponse.ResponseNo := 308;
   UniSession.AResponse.ResponseText := 'redirected';
   UniSession.TerminateAfterSecs(2);
   UniSession.UrlRedirect(RedirectURL);
  end;
 end;
end;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...