4
votes

I'm getting a 404 not found error when trying to access one of my Web API actions:

I have in my WebAPIConfig:

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

I have a controller named OnSourceAPIController and a GET action ValidateServiceRequestAuto.

I get a 404 error when I try to go to:

http://localhost/api/OnSourceAPI/ValidateServiceRequestAuto

My first guess was I had some kind of routing error, but I created an mvc controller and an index page for it and was able to browse there normally via this routing (api/controller/action). The builtin api/help page even shows /api/OnSourceAPI/ValidateServiceRequestAuto as the route to my api call.

I also tried using the WebAPIRouteDebugger tool. It gives me a 000 404 not found error when I use

http://localhost/api/OnSourceAPI/ValidateServiceRequestAuto

, but actually give me the normal route information if I take localhost off of the front and just use

api/OnSourceAPI/ValidateServiceRequestAuto as the URL...

Any pointers would be appreciated.

2

2 Answers

6
votes

I figured it out and feel a little bit silly now.

I have my webapi project running inside of my normal website project with a path of .../api, so because I set up my api routing to be api/controller/action, the path I really need to use is localhost/api/api/controller/action. So it turns out that the 404 was there because it really couldn't find anything at that location. I hate it when computers do exactly what you tell them to.

0
votes

In my case it was address of created service: WebApp.Start(address)

Should be like: http://localhost:9000/

NOT: http://localhost:9000/api/