Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Redirect in ASPNET Web API

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.

like image 208
Eric Avatar asked Jun 27 '13 15:06

Eric


People also ask

How do I redirect a razor page?

You can use the IActionResult to return a redirection or your razor page.

How we can redirect to another page or controller?

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.


1 Answers

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;
}
like image 175
Darin Dimitrov Avatar answered Oct 04 '22 23:10

Darin Dimitrov