我正在尝试在 DNN 中创建一个简单的 web-api,
这是我的代码: 1st Register RouteMapper(我设置了一个断点,它被调用没有问题)
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" });
}
}
}
第二个 Controller :
namespace Commission7.Controllers
{
[AllowAnonymous]
class SubmitController : DnnApiController
{
private readonly Commision7Context _dbContext = new Commision7Context();
[AllowAnonymous]
[HttpGet]
public bool SaveVisits()
{
return true;
}
}
}
当我通过 Ajax 或直接从浏览器中调用它时:
http://localhost/dnn/DesktopModules/Commission7/api/Submit/SaveVisits
我明白了:
Unable to locate a controller for http://localhost/dnn/DesktopModules/Commission7/api/Submit/SaveVisits. Searched in namespaces: Commission7.Controllers.
请注意,Module 文件夹名为 Commission 7,它位于 DesktopModules 文件夹中。谁能帮我这个?有没有我忘记的配置?
最佳答案
如果其他人遇到此问题,还要检查您是否具有该属性...
optimizeCompilations="true"
...在您的 web.config 文件中设置 <compilation>
标签。我一直收到错误...
dnn unable to locate a controller XXX searched in namespaces XXX
...直到我将其设置为 false.. 然后错误消失,因此我可以将其设置回 true。
关于dotnetnuke - DnnApiController 无法找到 "Path x"的 Controller 。在命名空间 : "Namespace y" 中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35100034/