.Net Core Web API-从Post方法重定向到外部URL [英] .Net Core Web API --Redirect to external url from Post Method

查看:1344
本文介绍了.Net Core Web API-从Post方法重定向到外部URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请建议如何使用.Net核心webapi从Post方法重定向到外部url. RedirectPermanent无法正常工作.

Please advice how to redirect to external url from Post method using .Net core webapi. RedirectPermanent is not working.

public class RegisterUserController : Controller
{

  public async Task<RedirectResult> Post([FromBody] user)
    {
      ---somecode
        string url = "http://www.gmail.com";
        return RedirectPermanent(url) ;//--is not working
   }
}

推荐答案

要重定向到特定的URL,请使用 RedirectResult 类:

For redirect to specific URL use the RedirectResult class:

public async Task<ActionResult> Post([FromBody] user)
{
     //...
     string url = "http://www.example.com";
     RedirectResult redirectResult = new RedirectResult(url, true);
     return redirectResult;
}

第二个参数指示重定向是否应该是永久的.

The second parameter indicates whether the redirection should be permanent or not.

这篇关于.Net Core Web API-从Post方法重定向到外部URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆