August 2017
Intermediate to advanced
330 pages
7h 26m
English
Sometimes, we might get routing requirements like different routes applied to the same controller or action methods. At first, it seems to be very surprising, but in large projects, we might need this kind of routing.
Multiple Routes can be achieved by putting multiple route attributes on the controller as shown in this code snippet:
[Route("Stocks")]
[Route("[controller]")]
public class PacktsController : Controller
{
[HttpGet("Check")]
[HttpGet("Available")]
public string GetStock()
{
return "Its multiple route";
}
}
Run the application to see the multiple routes in action. You would verify the multiple routes are working by accessing the endpoints on the browser as /api/stocks/check or /api/packts/available.
Read now
Unlock full access