I'm new to ASP.NET Web API but I'm hitting an issue where if I'm trying to add two get methods to a single controller it is failing at trying to get the action. Are we allowed only one get per controller, unless we are adding an overload of the same method?
This works if I only have one get method, e.g. the first one. As soon as I add Get to the second method name, it gives me a 500.
[HttpGet]
public string GetToday()
{
return "Hello today";
}
[HttpGet]
public string GetPending()
{
return "Hello Pending";
}
The calls I'm making: http://abc.com/api/tasks/gettoday http://abc.com/api/tasks/getpending
I can make this call if the method name is just 'Today', as long as I put the [HttpGet] attribute. But only if I don't have the second action. Which means if I remove the [HttpGet] attribute from the second method as well as remove 'Get' from the method name so it is just Pending, then it works.
As soon as there are two get methods I get this error:
{"Message":"An error has occurred.","ExceptionMessage":"Multiple actions were found that match the request: \r\nSystem.String TodaysTasks() on type TaskTrackerService.Controllers.TasksController\r\nSystem.String PendingTasks() on type TaskTrackerService.Controllers.TasksController","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)"}