简体   繁体   English

如何从 blazor webassembly 中的 controller 重定向到外部 url?

[英]How to Redirect to external url from controller in blazor webassembly?

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. 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,但是当我在 iis 服务器上发布应用程序时,确认链接不会将我重定向到欢迎页面,它停留在链接路径中,并且在应用程序中它显示我找不到路径。

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这是我将确认消息发送到邮件的代码,此链接位于 Send Mail 方法中,其中包含发送电子邮件的所有信息

 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:在控制台中,它向我显示一切都成功了,它向我显示了它的真实路径和状态 200,但它向我显示了一个警告:

在此处输入图像描述

在此处输入图像描述

until I forcefully update it takes me to the correct path

在此处输入图像描述

I already tried to use other redirection methods, thinking that the problem comes from the http states that each method returns, use the following:我已经尝试使用其他重定向方法,认为问题来自 http 声明每个方法返回,使用以下:

Redirect() 302 
RedirectPermanent()  301
RedirectPreserveMethod 307

Just a thought, since you only have the code from the controller posted.只是一个想法,因为您只发布了 controller 中的代码。 You have allowed anonymous in the controller... but did you do so in the web page?您已在 controller 中允许匿名...但是您是否在 web 页面中这样做了?

@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.我确实发现 这篇我认为可能很有帮助的文章......但是在这篇文章中,他们正在从服务器执行页面重定向......这就是为什么当我遇到时我正在研究是否可以在 WASM 中从服务器重定向这个帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM