Is there a Web API controller method equivalent to the MVC controller method RedirectToAction? I would like to call one method from another, but retain the filter actions for the secondary method.
You can use the IActionResult to return a redirection or your razor page.
Redirect() method The first method od redirecting from one URL to another is Redirect(). The Rediect() method is available to your controller from the ControllerBase class. It accepts a target URL where you would like to go.
Is there a Web API controller method equivalent to the MVC controller method RedirectToAction?
You could set the Location header:
public HttpResponseMessage Get()
{
var response = Request.CreateResponse(HttpStatusCode.Found);
response.Headers.Location = new Uri("http://www.google.com");
return response;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With