Search code examples
piranha-cms

Piranha CMS Management Custom Controller Not Found


I am having an issue with adding a custom controller to my Piranha CMS. I have set up a new site and installed from the template and all the base functionality is working well. I have added the menu to the manager section using the following code from the documentation:

        Manager.Menu.Add(new Manager.MenuGroup()
        {
            InternalId = "MEProducts",
            Name = "Products"
        });

        Manager.Menu.Where(m => m.InternalId == "MEProducts").Single().Items =
           new List<Manager.MenuItem>() {
            new Manager.MenuItem() {
              Name = "Products",
              Action = "productlist",
              Controller = "products",
              Permission = "ADMIN",
              SelectedActions = "productlist,productedit"
            },
            new Manager.MenuItem() {
              Name = "Product groups",
              Action = "productgrouplist",
              Controller = "products",
              Permission = "ADMIN",
              SelectedActions = "productgrouplist,productgroupedit"
            }
          };

This menu displays in the manager interface fine, the problem is when I click on the menu item the controller path can not be found.

The controller is class is in Areas/Manager/Controllers/ProductsController.cs and the code is below

namespace MyApp.Areas.Manager.Controllers
{
public class ProductsController : ManagerController
{
    //
    // GET: /Manager/Products/

    public ActionResult Index()
    {
        return View();
    }
    public ActionResult ProductList()
    {
        return View();
    }
    public ActionResult ProductEdit(string id = "")
    {
        return View();
    }
}
}

There are view files for ProductList and ProductEdit in Areas/Manager/Views/Products/

My web config contains the following line that I believe I need

<add key="manager_namespaces" value="MyApp.Areas.Manager.Controllers" />

When I click on the Products link in the manager I get

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /MyApp/manager/products/productlist

The page /MyApp/manager/page displays fine for the default configuration.

I am sure that I have missed something, or done something incorrect somewhere I'm just not sure where it is.


Solution

  • I've tried reproduce your issues but it works perfectly with your productscontroller in my project. I've zipped my test-project and uploaded it to my dropbox so you can download and compare it to your project:

    EDIT Removed download link as author downloaded the file

    Please let me know when you've downloaded the zip-file so I can delete it.

    Regards

    Håkan