Home > OS >  ASP.NET MVC controller not accessible?
ASP.NET MVC controller not accessible?

Time:04-06

I am trying to reach an controller from my umbraco backoffice, but it seems impossible to do so.

The controller I have created is a simple

using System.Diagnostics;
using System.Web.Http;
using System.Web.Mvc;
using Umbraco.Web.Mvc;

namespace UniversalRobots.Events.Controllers
{
    public class TreeController : UmbracoAuthorizedController
    {
        public ActionResult GetCurrentContentTree()
        {
            Debugger.Break();
            return Content("Somthing");
        }
    }
}

Which according to the documentation (https://our.umbraco.com/Documentation/Reference/Routing/Authorized/index-v8) should be available from

/umbraco/backoffice/api/{controller}/{action}

or in the case of a plugincontroller be available from

/umbraco/backoffice/{pluginname}/{controller}/{action}

I have for now tried this

https://localhost:44313/umbraco/backoffice/api/Tree/GetCurrentContentTree

and

https://localhost:44313/umbraco/backoffice/Tree/GetCurrentContentTree 

both of which return an error:

HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

What is the controller endpoint?

CodePudding user response:

Turned out to be wrong interface I was inheriting instead of UmbracoAuthorizedController it should have been UmbracoAuthorizedApiController

CodePudding user response:

Did you define the route?

public class RegisterCustomBackofficeMvcRouteComponent : IComponent
{
    private readonly IGlobalSettings _globalSettings;

    public RegisterCustomBackofficeMvcRouteComponent(IGlobalSettings globalSettings)
    {
        _globalSettings = globalSettings;
    }

    public void Initialize()
    {
        RouteTable.Routes.MapRoute("[yourPluginName]", 
            _globalSettings.GetUmbracoMvcArea()   "/backoffice/[yourpluginname]/{controller}/{action}/{id}", 
            new
            {
                controller = "[yourpluginname]",
                action = "Index",
                id = UrlParameter.Optional },
            constraints: new { controller="[yourcontrollername]" });
    }

    public void Terminate()
    {
        // Nothing to terminate
    }
}

The correct syntax does appear to be /umbraco/backoffice/{pluginname}/{controller}/{action}

Your endpoint should therefore theoretically be

/umbraco/backoffice/api/Tree/GetCurrentContentTree 
  • Related