Search code examples
dotnetnukedotnetnuke-7

DnnApiController Unable to locate a controller for "Path x". Searched in namespaces: " Namespace y"


I am trying to create a simple web-api in DNN,

Here are my codes : 1st Register RouteMapper (I set a break-point it is being called without problem)

namespace Commission7.Controllers
{
   public class RouteMapper : IServiceRouteMapper
   {
       public void RegisterRoutes(IMapRoute mapRouteManager)
       {
          mapRouteManager.MapHttpRoute("Commission7", "default", "{controller}/{action}/{id}", new { id = RouteParameter.Optional }, new[] { "Commission7.Controllers" });
       }
   }
}

2nd The Controller :

namespace Commission7.Controllers
{
   [AllowAnonymous]
   class SubmitController : DnnApiController
   {
       private readonly Commision7Context _dbContext = new Commision7Context();

       [AllowAnonymous]
       [HttpGet]
       public bool SaveVisits()
       {
          return true;
       }
    }
}

And when I call it through Ajax or Direct hit from Browser with this:

http://localhost/dnn/DesktopModules/Commission7/api/Submit/SaveVisits

I get :

Unable to locate a controller for http://localhost/dnn/DesktopModules/Commission7/api/Submit/SaveVisits.  Searched in namespaces: Commission7.Controllers.

note that the Module folder is named Commission 7 and it is in the DesktopModules folder. Can anyone help me with this? Is there any config that I forgot?


Solution

  • I found the problem , class SubmitController was private class , it should be public to be available for ajax and direct call.