0

Error Message

{
    "Message": "No HTTP resource was found that matches the request URI 'https://localhost:44390/api/UserRoutes?effectiveDate=3/29/2019'.",
    "MessageDetail": "No type was found that matches the controller named 'UserRoutes'."
}

Working Action

public class AdvanceOrderApiController : BaseApiController
{
    [HttpGet, Route("api/AdvanceOrders")]
    public AdvanceOrdersResult GetAdvanceOrdersForRouteDate(string route, DateTime effectiveDate)
    {
        ...
    }
}

// JavaScript Usage: route="0100" and effectiveDate="03/29/2019".
API.SendRequest("/api/AdvanceOrders", "GET", { route: route, effectiveDate: effectiveDate }, success, failure);

Not Working Action

public class UserApiController : BaseApiController
{
    [HttpGet, Route("api/UserRoutes")]
    public IEnumerable<string> GetUserRoutes(DateTime effectiveDate)
    {
        ...
    }
}

// JavaScript Usage: effectiveDate="03/29/2019"
API.SendRequest("/api/UserRoutes", "GET", { effectiveDate: effectiveDate }, success, failure);

WebApiConfig

Not sure that it's relevant since I'm just declaring the route for each action, but...

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.MapHttpAttributeRoutes();

        ...

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }
}

API.SendRequest

This function is just a wrapper around jQuery's $.ajax function, nothing fancy. If the code is necessary I'll present it, but it works for all my other API calls so I can't imagine it would be the source of the problem.

These actions are nearly identical, why does one work and the other doesn't?

Shelby115
  • 2,816
  • 3
  • 36
  • 52
  • Possible duplicate of [How to pass a datetime parameter?](https://stackoverflow.com/questions/14359566/how-to-pass-a-datetime-parameter) – Igor Mar 29 '19 at 17:54
  • Use ISO8601 to format your date string when you send it as a part of the URL. `https://localhost:44390/api/UserRoutes?effectiveDate=2019-03-29` – Igor Mar 29 '19 at 17:56
  • Going to the link you sent gave me a useful error apparently I have a controller named `UserApiController` in another area and the routing can't handle that. So thanks a ton, I guess routing was having issues resolving that action because it was loading the one in my `Permissions` area and not finding my requested action. – Shelby115 Mar 29 '19 at 18:12

1 Answers1

0

Passing the date in as Igor said in the comments presented an error message that revealed that I had an Api controller in my Permissions area that had a route also named api/UserRoutes.

Once I changed the name of the route the problem resolved. I just wish it could have just told me this error message from the start.

Shelby115
  • 2,816
  • 3
  • 36
  • 52