How to Redirect to external url from controller in blazor webassembly?

Viewed 764

I know that this question has already been asked but no answer has helped me to solve my problem.

I am using blazor webassembly, in the login module I send a confirmation email to the new user, in the message that comes to the email comes a confirmation link, which redirects to a custom blazor confirmation page that welcomes the system, everything works fine in localhost, but when I publish the app on an iis server, the confirmation link does not redirect me to the welcome page, it stays in the link path, and in the app it shows me that it could not find the path.

Could you please help me

this is my code to send the confirmation message to the mail, This link is within a Send Mail method which contains all the information to send emails

 var confirmationUrl = $"https://{Request.Host.Value}/api/Cuentas/VerifyEmailAsync?userId={HttpUtility.UrlEncode(userIdentity.Id)}&emailToken={HttpUtility.UrlEncode(emailVerificationCode)}";

This endpoint is the one that redirects to the welcome page once the user clicked on the link that I describe above in this publication:

 [AllowAnonymous]
        [Route("VerifyEmailAsync")]
        [HttpGet]
        public async Task<ActionResult> VerifyEmailAsync(string userId, string emailToken)
        {
            // Get the user
            var user = await _userManager.FindByIdAsync(userId);

            // If the user is null
            if (user == null)
                // TODO: Nice UI
                return Content("Usuario no encontrado");

            // If we have the user...

            // Verify the email token
            var result = await _userManager.ConfirmEmailAsync(user, emailToken);

            // If succeeded...
            if (result.Succeeded)
            {
                //se usa redirect para enviar a una pagina blazor desde el controlador
                //return Content("Correo Verificado");
                return Redirect($"https://{Request.Host.Value}/cuentaconfirmada");
            }

            // TODO: Nice UI
            return Content("Token de verificación de correo electrónico no válido");
        }

clicking on the link takes me to the following route:

https://beta.dominio.mx/api/Cuentas/VerifyEmailAsync?userId=7cc3a7b0-7f40-4d23-abe4-f6778877d6fa&emailToken=CfDJ8BaQjrGRmsNBsbOJm8bucuOua9CJS4w%2fvwySE%2bk0I%2btQYzfBc%2bysKqkCR9nwHDP7wmHzAkgYo%2fUiURHwnQd113wslk8Lgo5iqgAPxKWX17x0PYFF8y%2bih9BFtzD4RiOn%2bZXsZLDWqcga1tjHcDmYfhzh9NwWFZv8AhdLF48BusPZ9bsXiHEUK1WVY8Wgi7j601p%2fRds%2f7TY3rjq6BqpSyHiud3stD16xL5jgn1fLbinlzgm5%2bHvWegmXa2WICgL01A%3d%3d

the original route where it should take me is:

https://beta.dominio.mx/cuentaconfirmada

in the console it shows me that everything was successful it shows me the path that it really is and a status of 200 but it shows me a warning:

enter image description here

enter image description here

until I forcefully update it takes me to the correct path

enter image description here

I already tried to use other redirection methods, thinking that the problem comes from the http states that each method returns, use the following:

Redirect() 302 
RedirectPermanent()  301
RedirectPreserveMethod 307
1 Answers

Just a thought, since you only have the code from the controller posted. You have allowed anonymous in the controller... but did you do so in the web page?

@layout AllowAnonLayout

I am attempting something similar. However in my case everything seems to work, but sometimes the redirection hangs after the user has been authenticated and I get a blank page.

I did find this article which I think may be pretty helpful... but in this article they are performing the page redirects from the server... which is why I am researching if redirecting from the server is possible in WASM when I came across this post.

Related