Plugin: admin routes - Page Not Found

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 лет назад
Hi All,

I'm creating a plugin with a number of routes for listing, adding, creating, deleting, ... within the admin area, but they don't work. I'm i doing something wrong?


// index
routes.MapRoute("CustomerServiceAdmin",
    "admin/Plugins/CustomerService/{action}/{id}",
    new {controller = "_CustomerServiceAdmin", action = "Index", id = UrlParameter.Optional},
    new[] {"Nop.Plugin.Misc.CustomerService.Controllers"})
    .DataTokens.Add("area", "admin");

// list
routes.MapRoute("CustomerServiceAdmin.List",
    "admin/Plugins/CustomerService/{action}/{id}",
    new {controller = "_CustomerServiceAdmin", action = "List", id = UrlParameter.Optional},
    new[] {"Nop.Plugin.Misc.CustomerService.Controllers"})
    .DataTokens.Add("area", "admin");

// create
routes.MapRoute("CustomerServiceAdmin.Create",
    "admin/Plugins/CustomerService/{action}/{id}",
    new {controller = "_CustomerServiceAdmin", action = "Create", id = UrlParameter.Optional},
    new[] {"Nop.Plugin.Misc.CustomerService.Controllers"})
    .DataTokens.Add("area", "admin");

// edit
routes.MapRoute("CustomerServiceAdmin.Edit",
    "admin/Plugins/CustomerService/{action}/{id}",
    new { controller = "_CustomerServiceAdmin", action = "Edit", id = UrlParameter.Optional},
    new[] { "Nop.Plugin.Misc.CustomerService.Controllers" })
    .DataTokens.Add("area", "admin");

// delete
routes.MapRoute("CustomerServiceAdmin.Delete",
    "admin/Plugins/CustomerService/{action}/{id}",
    new { controller = "_CustomerServiceAdmin", action = "Delete", id = UrlParameter.Optional },
    new[] { "Nop.Plugin.Misc.CustomerService.Controllers" })
    .DataTokens.Add("area", "admin");


Log Error:

The controller for path '/Admin/Plugins/CustomerService' was not found or does not implement IController.

System.Web.HttpException (0x80004005): The controller for path '/Admin/Plugins/CustomerService' was not found or does not implement IController. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
10 лет назад
Nesse wrote:
Hi All,

I'm creating a plugin with a number of routes for listing, adding, creating, deleting, ... within the admin area, but they don't work. I'm i doing something wrong?


// index
routes.MapRoute("CustomerServiceAdmin",
    "admin/Plugins/CustomerService/{action}/{id}",
    new {controller = "_CustomerServiceAdmin", action = "Index", id = UrlParameter.Optional},
    new[] {"Nop.Plugin.Misc.CustomerService.Controllers"})
    .DataTokens.Add("area", "admin");

// list
routes.MapRoute("CustomerServiceAdmin.List",
    "admin/Plugins/CustomerService/{action}/{id}",
    new {controller = "_CustomerServiceAdmin", action = "List", id = UrlParameter.Optional},
    new[] {"Nop.Plugin.Misc.CustomerService.Controllers"})
    .DataTokens.Add("area", "admin");

// create
routes.MapRoute("CustomerServiceAdmin.Create",
    "admin/Plugins/CustomerService/{action}/{id}",
    new {controller = "_CustomerServiceAdmin", action = "Create", id = UrlParameter.Optional},
    new[] {"Nop.Plugin.Misc.CustomerService.Controllers"})
    .DataTokens.Add("area", "admin");

// edit
routes.MapRoute("CustomerServiceAdmin.Edit",
    "admin/Plugins/CustomerService/{action}/{id}",
    new { controller = "_CustomerServiceAdmin", action = "Edit", id = UrlParameter.Optional},
    new[] { "Nop.Plugin.Misc.CustomerService.Controllers" })
    .DataTokens.Add("area", "admin");

// delete
routes.MapRoute("CustomerServiceAdmin.Delete",
    "admin/Plugins/CustomerService/{action}/{id}",
    new { controller = "_CustomerServiceAdmin", action = "Delete", id = UrlParameter.Optional },
    new[] { "Nop.Plugin.Misc.CustomerService.Controllers" })
    .DataTokens.Add("area", "admin");


Log Error:

The controller for path '/Admin/Plugins/CustomerService' was not found or does not implement IController.

System.Web.HttpException (0x80004005): The controller for path '/Admin/Plugins/CustomerService' was not found or does not implement IController. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


Your URL can't start with Admin (or you need special care if you want to) as it's already been taken by all the Nop.Web controllers. Remove /admin/ from your URL, and it should work. :)
10 лет назад
Hi wooncherk,

I've tried to remove the admin part, but it's still not working.

Kind regards
10 лет назад
Nesse wrote:
Hi wooncherk,

I've tried to remove the admin part, but it's still not working.

Kind regards


Why do you have the same URL format for all the different Url? You can just remove all and leave one of them if you want to use this kind of placeholder configuration.
10 лет назад
Nesse wrote:
Hi wooncherk,

I've tried to remove the admin part, but it's still not working.

Kind regards


And you don't need to configure the area as admin.
10 лет назад
wooncherk wrote:
Hi wooncherk,

I've tried to remove the admin part, but it's still not working.

Kind regards

And you don't need to configure the area as admin.


Thx wooncherk,

So like this? One Route?


routes.MapRoute("CustomerServiceAdmin",
                "Plugins/CustomerService/{action}/{id}",
                new {controller = "_CustomerServiceAdmin", id = UrlParameter.Optional},
                new[] {"Nop.Plugin.Misc.CustomerService.Controllers"});
10 лет назад
Nesse wrote:
Hi wooncherk,

I've tried to remove the admin part, but it's still not working.

Kind regards

And you don't need to configure the area as admin.

Thx wooncherk,

So like this? One Route?


routes.MapRoute("CustomerServiceAdmin",
                "Plugins/CustomerService/{action}/{id}",
                new {controller = "_CustomerServiceAdmin", id = UrlParameter.Optional},
                new[] {"Nop.Plugin.Misc.CustomerService.Controllers"});


You can give it a try, I think it should work. :)
10 лет назад
It's still not working. I've debugged my plugin, and it never hits RegisterRoutes. Not on install, reloading all plugins, ... So strange. It should at least have one hit. My RouteProvicer.cs file is set to compile.
10 лет назад
Nesse wrote:
It's still not working. I've debugged my plugin, and it never hits RegisterRoutes. Not on install, reloading all plugins, ... So strange. It should at least have one hit. My RouteProvicer.cs file is set to compile.


Can you post the full content of your RouteProvider.cs?
10 лет назад
wooncherk wrote:
It's still not working. I've debugged my plugin, and it never hits RegisterRoutes. Not on install, reloading all plugins, ... So strange. It should at least have one hit. My RouteProvicer.cs file is set to compile.

Can you post the full content of your RouteProvider.cs?


I've made more than a dozen plugins, but never came across this problem.


using System.Web.Mvc;
using System.Web.Routing;
using Nop.Web.Framework.Mvc.Routes;

namespace Nop.Plugin.Misc.CustomerService
{
    public partial class RouteProvider : IRouteProvider
    {
        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute("Nop.Plugin.Misc.CustomerService.Test",
                 "Plugins/CustomerService/Test",
                 new { controller = "Test", action = "Test" },
                 new[] { "Nop.Plugin.Misc.CustomerService.Controllers" }
            );

          
        }
        public int Priority
        {
            get
            {
                return 0;
            }
        }
    }
}


Controller:


using System.Web.Mvc;
using Nop.Plugin.Misc.CustomerService.Models;

namespace Nop.Plugin.Misc.CustomerService.Controllers
{
    public class TestController : Controller
    {

        public ActionResult Test()
        {
            var model = new PageListModel();
          
            return View("Nop.Plugin.Misc.CustomerService.Views._CustomerServiceAdmin.List", model);

        }

    }
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.