Kentico WebApi documentation out of date - Example methods do not work 404

Jason Espin asked on October 4, 2018 13:05

I have followed the Kentico documentation word for word in order to attempt to setup a custom WebApi method in Kentico 11:

I have a class library project which contains two files:

CustomWebAPiController CustomWebApiModule

It references: CMS.Base CMS.Core CMS.DataEngine

This class library is referenced by my Kentico CMS project.

When I build and run the project and try and access my custom web api method via the url I get my sites 404 page. I have used exactly the same code as is shown in the Kentico documentation leading me to believe either:

  1. The documentation is out of date and there are steps missing
  2. There is extra CMS admin stuff that needs to be added in
  3. It just doesn't work and never has

A colleague of mine attempted the same thing and had to basically write his own routing engine on top of Kentico in order to get this to work which I do not want to do. There must be something I or the documentation is missing.

Can anyone assist with this as it is very frustrating that something that should be so simple seems to require a massive work around.

Correct Answer

Jason Espin answered on October 4, 2018 15:11

Turns out it was a versioning issue with the same version of WebApi not being used in CMS and my custom project.

0 votesVote for this answer Unmark Correct answer

Recent Answers

David te Kloese answered on October 4, 2018 13:23

Since this is somewhat going outside Kentico have you checked adding the following to your web.config

   <modules runAllManagedModulesForAllRequests="true">
0 votesVote for this answer Mark as a Correct answer

Jason Espin answered on October 4, 2018 13:26 (last edited on October 4, 2018 13:28)

Hi David,

My modules section looks like this:

<modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule" />
      <remove name="XHtmlModule" />
      <remove name="CMSApplicationModule" />
      <add name="XHtmlModule" type="CMS.OutputFilter.OutputFilterModule, CMS.OutputFilter" />
      <add name="CMSApplicationModule" preCondition="managedHandler" type="CMS.Base.ApplicationModule, CMS.Base" />

I am literally just trying to replicate what it says inside Kentico's own documentation but to no avail.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on October 4, 2018 15:08

Just got it running on my machine...

Image Text

didn't need runAllManagedModulesForAllRequests btw..

things to check:

  • did you install nugetpackage Microsoft.AspNet.WebApi on both the lib project and CMS app project
  • did you add a reference to CMS project to the lib project
0 votesVote for this answer Mark as a Correct answer

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