user6511101
user6511101

Reputation: 23

Redirecting to different controller in webapi in asp.net

I'm new to WebApi in Asp.Net and my scenario is like this. I've a webapi application with 2 controllers say Controller1 and Controller2 and controller1 has a method called Index and controller2 has GetProducts method. So when a client calls url : api/controller1/Index then they should be redirected to a getProducts method in Controller2 .I know that they can call controller2 directly but My requirement is in such a way that they should call controller1 initially and when they are redirected to controller2 ,the url should be like api/controller2/GetProducts . Please tell me how to get this.

Upvotes: 1

Views: 3754

Answers (1)

icaru12
icaru12

Reputation: 1582

You can use the ApiController.Redirect() method.

return Redirect(
    Url.Link("DefaultApi", new { controller = "Controller2", action = "GetProducts" })
);

Upvotes: 3

Related Questions