I'm trying to create a group of custom dashboard boards. I've created a separated class library and referenced it in my Umbraco web project.
namespace Dashboards
{
[Umbraco.Web.Mvc.PluginController("Dashboard")]
[IsBackOffice]
public class WelcomeController : UmbracoApiController
{
public int countPublishedNodes()
{
var contentService = Services.ContentService;
int PublishedNodes = contentService.CountPublished();
return PublishedNodes;
}
}
}
However I'm getting a 404 error when I try and access the method
/umbraco/backoffice/api/Dashboard/Welcome/countPublishedNodes
can anyone see why? do I need to map it in an startup event ?
Hi John,
I've not used the [IsBackOffice] with UmbracoApiController but I've had great success using the UmbracoAuthorizedApiController .
Try the following code:
namespace Dashboard {
[Umbraco.Web.Mvc.PluginController("Dashboard")]
public class WelcomeController : Umbraco.Web.WebApi.UmbracoAuthorizedApiController {
[System.Web.Http.HttpGet]
public int countPublishedNodes() {
var contentService = Services.ContentService;
int PublishedNodes = contentService.CountPublished();
return PublishedNodes;
}
}
}
[HttpGet] is required as by default it's considered a HTTP Post request and will disallow any access. UmbracoAuthorisedApiController will ensure the user is authorized before they make the request.
Custom Dashboard using WebApi
I'm trying to create a group of custom dashboard boards. I've created a separated class library and referenced it in my Umbraco web project.
However I'm getting a 404 error when I try and access the method /umbraco/backoffice/api/Dashboard/Welcome/countPublishedNodes
can anyone see why? do I need to map it in an startup event ?
Hi John,
I've not used the
[IsBackOffice]
withUmbracoApiController
but I've had great success using theUmbracoAuthorizedApiController
.Try the following code:
[HttpGet]
is required as by default it's considered a HTTP Post request and will disallow any access.UmbracoAuthorisedApiController
will ensure the user is authorized before they make the request.I hope this helped :)
Thanks,
Jamie
Thanks for the reply I'll give it ago in the next few days!
Awesome, if it helps you out mark it as the solution. Otherwise let me know and we'll see what we can do, eh?
is working on a reply...