cklester Well-Known Member Licensed User Jan 22, 2021 #1 I've got users clicking a confirmation link from their email. I'm processing the click, but I want to send them to a Success or Fail page, depending on the result of the confirmation check. I've seen the SendRedirect, but I don't want to send a code 302. It should just be normal. For example, they click: https://MySuperApp.com/confirm?code=93njgf93iufhg9038fdh and my confirm handler processes that, and then sends them either to https://MySuperApp.com/thankyou or https://MySuperApp.com/bad-confirmation How do I handle that?
I've got users clicking a confirmation link from their email. I'm processing the click, but I want to send them to a Success or Fail page, depending on the result of the confirmation check. I've seen the SendRedirect, but I don't want to send a code 302. It should just be normal. For example, they click: https://MySuperApp.com/confirm?code=93njgf93iufhg9038fdh and my confirm handler processes that, and then sends them either to https://MySuperApp.com/thankyou or https://MySuperApp.com/bad-confirmation How do I handle that?
aeric Expert Licensed User Longtime User Jan 22, 2021 #2 It depends on the returned result. Let say the results can be either “success” or “failed” from a DBResult type or JSON string. Base on this you can do what ever redirects you want. Upvote 0
It depends on the returned result. Let say the results can be either “success” or “failed” from a DBResult type or JSON string. Base on this you can do what ever redirects you want.
cklester Well-Known Member Licensed User Jan 22, 2021 #3 How do I do a Redirect without throwing a code 302? The docs say that Redirect throws a code 302. If I change the status code with something like resp.Status = 200 will that override the 302 thrown by the Redirect? Upvote 0
How do I do a Redirect without throwing a code 302? The docs say that Redirect throws a code 302. If I change the status code with something like resp.Status = 200 will that override the 302 thrown by the Redirect?
aeric Expert Licensed User Longtime User Jan 22, 2021 #4 Make both cases response with Status 200. Upvote 0
cklester Well-Known Member Licensed User Jan 25, 2021 #5 This doesn't work: Code: Copy Sub Handle(req As ServletRequest, resp As ServletResponse) resp.Status = 200 resp.SendRedirect("docs.html") End Sub Neither does switching those statements. So, how do I make it serve the docs.html page WITHOUT throwing a status code of 302? The user gets to https://mysite.com/docs, and I need to redirect (without a status code 302) to https://mysite.com/docs.html. I guess I could put that in my nginx config file, but I shouldn't have to from what I understand about the process. I've done this with Laravel (PHP), so I know it's possible... or am I remembering wrong? Last edited: Jan 25, 2021 Upvote 0
This doesn't work: Code: Copy Sub Handle(req As ServletRequest, resp As ServletResponse) resp.Status = 200 resp.SendRedirect("docs.html") End Sub Neither does switching those statements. So, how do I make it serve the docs.html page WITHOUT throwing a status code of 302? The user gets to https://mysite.com/docs, and I need to redirect (without a status code 302) to https://mysite.com/docs.html. I guess I could put that in my nginx config file, but I shouldn't have to from what I understand about the process. I've done this with Laravel (PHP), so I know it's possible... or am I remembering wrong?
aeric Expert Licensed User Longtime User Jan 25, 2021 #6 Maybe I misunderstood what you are trying to do. If you have processed user's click action, you now have 2 results, "success" or "failed". I think you can base on these 2 cases and write the HTML response with 2 different URL. I think it will give you code 200 at first run. HTML: Copy <meta http-equiv="Refresh" content="0; url='https://mysite.com/docs.html'" /> B4X: Copy resp.ContentType = "text/html" resp.Write($"<meta http-equiv="Refresh" content="0; url='https://mysite.com/docs.html'" />"$) Edit: Add resp.ContentType = "text/html" Last edited: Jan 25, 2021 Upvote 0
Maybe I misunderstood what you are trying to do. If you have processed user's click action, you now have 2 results, "success" or "failed". I think you can base on these 2 cases and write the HTML response with 2 different URL. I think it will give you code 200 at first run. HTML: Copy <meta http-equiv="Refresh" content="0; url='https://mysite.com/docs.html'" /> B4X: Copy resp.ContentType = "text/html" resp.Write($"<meta http-equiv="Refresh" content="0; url='https://mysite.com/docs.html'" />"$) Edit: Add resp.ContentType = "text/html"
cklester Well-Known Member Licensed User Jan 25, 2021 #7 aeric said: B4X: Copy resp.ContentType = "text/html" resp.Write($"<meta http-equiv="Refresh" content="0; url='https://mysite.com/docs.html'" />"$) Click to expand... Yep! You got it! That works! Thank you! @Erel , maybe we could have something like this: Code: Copy resp.SendRefresh("docs.html") I'm using this after a person completes a registration. The user gets an email with a URL like: Code: Copy https://mysite.com/confirm?code=shfg9834hkdjfhg93845hsldkdfgh9384h987hg They click on it, and it hits the /confirm route, but then needs to show a success.html or fail.html page, as applies. Would it be better, instead of doing a <meta> refresh, to load the file myself and send it? Code: Copy resp.ContentType = "text/html" resp.Write( File.LoadString("success.html") ) Upvote 0
aeric said: B4X: Copy resp.ContentType = "text/html" resp.Write($"<meta http-equiv="Refresh" content="0; url='https://mysite.com/docs.html'" />"$) Click to expand... Yep! You got it! That works! Thank you! @Erel , maybe we could have something like this: Code: Copy resp.SendRefresh("docs.html") I'm using this after a person completes a registration. The user gets an email with a URL like: Code: Copy https://mysite.com/confirm?code=shfg9834hkdjfhg93845hsldkdfgh9384h987hg They click on it, and it hits the /confirm route, but then needs to show a success.html or fail.html page, as applies. Would it be better, instead of doing a <meta> refresh, to load the file myself and send it? Code: Copy resp.ContentType = "text/html" resp.Write( File.LoadString("success.html") )
aeric Expert Licensed User Longtime User Jan 25, 2021 #8 B4X: Copy resp.Write(Content) The Response.Write is very powerful and generally it can return different types of content like JSON, text, image, file and HTML. It all depend how you set the content type. B4X: Copy resp.ContentType = "CONTENT TYPE" Upvote 0
B4X: Copy resp.Write(Content) The Response.Write is very powerful and generally it can return different types of content like JSON, text, image, file and HTML. It all depend how you set the content type. B4X: Copy resp.ContentType = "CONTENT TYPE"