Web API Issues Including MVC

Pzill4 Pzill4 asked on October 1, 2014 22:23

I'm having issues getting routing to behave for Web API in Kentico 8.

My routes seem ok. Here is what I have in the Register (confirmed execution) Method WebApiConfig.cs file: config.Routes.MapHttpRoute("Default API", "api/Test/{id}", new {RouteParameter.Optional});

My api controller:

TestController:ApiController was created using the standard v1 WebApi VS2013 template. Typical stuff, tried the file in a stand-alone solution and works fine.

I suppose to explain my error, I get a 404, as if the Route wasn't properly registered, although it is. I've tested OOTB method ie http://localhost/cmsapi/tile and works.

I don't know what else to do.

Any thoughts?


Recent Answers

Pzill4 Pzill4 answered on October 1, 2014 23:14

Also, if I add a the MVC route

{controller}/{action}/{id} (optional id), the ~/cmsapi/tile breaks 404...

0 votesVote for this answer Mark as a Correct answer

Martyn Roberts answered on October 14, 2014 19:58

The issue here is because the route starts with "api" - change it to something else and it will work

0 votesVote for this answer Mark as a Correct answer

Pzill4 Pzill4 answered on October 15, 2014 18:11

The answer is this:

[assembly: RegisterApiController(typeof(LiveTileController))]

The reason is, as is the norm, that .NET searches the assemblies for anything deriving in APIController when routes are registered. Because of the many CMS assemblies, it was very inefficient to search them all for APIControllers.


1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.