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.