问题
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