Mahyar Pasarzangene
Mahyar Pasarzangene

Reputation: 393

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?

Upvotes: 3

Views: 1233

Answers (2)

Yankee516
Yankee516

Reputation: 80

If anyone else comes across this, also check whether you have the attribute...

optimizeCompilations="true"

...set in your web.config file's <compilation> tag. I kept getting the error...

dnn unable to locate a controller XXX searched in namespaces XXX

...until I set it to false.. Then the error went away so I could set it back to true.

Upvotes: 4

Mahyar Pasarzangene
Mahyar Pasarzangene

Reputation: 393

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

Upvotes: 2

Related Questions