.Net Core Web API --Redirect to external url from Post Method

久未见 提交于 2020-01-16 05:29:05

问题


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
   }
}

回答1:


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.



来源:https://stackoverflow.com/questions/49172872/net-core-web-api-redirect-to-external-url-from-post-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!