Plugin and RouteProvider

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi guys,

I have a plugin in NopCommerce 2.1 with a customize configuration page which is accessed through an URL. Most of the URL RouteProvider I saw in NopCommerce 2.1 follows the standard Plugins/NameOfThePlugin/Configure. The URL turns out to be not under Admin/. I'd like to be able to access the Plugin Configuration page which is not a [ChildActionOnly] through an URL which is as follow Admin/Plugins/NameOfThePlugin/Configure. I can't figure out a way to do this.

Please let me know. Thanks in advance

Tri
12 years ago
Hi Tri,

You need to add a data token to your route.
Here is a code sample how to do this in the RegisterRoutes method of your RouteProvider class.

var route = routes.MapRoute(YourRouteName,
                  "admin/Plugins/YourPluginName/YourControllerName/YourActionName",
                  new { controller = "YourControllerName", action = "YourActionName" },
                  new[] { TheNamespaceOfYourControllerClass }
             );

route.DataTokens.Add("area", "admin");

Hope this helps!
12 years ago
7Spikes wrote:
Hi Tri,

You need to add a data token to your route.
Here is a code sample how to do this in the RegisterRoutes method of your RouteProvider class.

var route = routes.MapRoute(YourRouteName,
                  "admin/Plugins/YourPluginName/YourControllerName/YourActionName",
                  new { controller = "YourControllerName", action = "YourActionName" },
                  new[] { TheNamespaceOfYourControllerClass }
             );

route.DataTokens.Add("area", "admin");

Hope this helps!


Thanks so much :). It works
12 years ago
triho wrote:
Hi Tri,

You need to add a data token to your route.
Here is a code sample how to do this in the RegisterRoutes method of your RouteProvider class.

var route = routes.MapRoute(YourRouteName,
                  "admin/Plugins/YourPluginName/YourControllerName/YourActionName",
                  new { controller = "YourControllerName", action = "YourActionName" },
                  new[] { TheNamespaceOfYourControllerClass }
             );

route.DataTokens.Add("area", "admin");

Hope this helps!

Thanks so much :). It works


I'm having the same problem :S

Here my route provider:

public void RegisterRoutes(RouteCollection routes)
        {
            var route = routes.MapRoute("Plugin.UI.DynamicCategoryMenu.Configure",
                 "Admin/DynamicCategoryMenu/Configure",
                 new { controller = "Menu", action = "Configure" },
                 new[] { "Nop.Plugin.UI.DynamicCategoryMenu.Controllers" }
            );
            route.DataTokens.Add("area", "Admin");

            routes.MapRoute("Plugin.UI.DynamicCategoryMenu.PublicInfo",
                 "Plugins/DynamicCategoryMenu/PublicInfo",
                 new { controller = "Menu", action = "PublicInfo" },
                 new[] { "Nop.Plugin.UI.DynamicCategoryMenu.Controllers" }
            );
        }
        public int Priority
        {
            get
            {
                return 0;
            }
        }


When I load http://localhost/Admin/DynamicCategoryMenu/Configure, I get a 404...

If I change my route provider to Plugins/DynamicCategoryMenu/Configure, I can load the page @ http://localhost/Plugins/DynamicCategoryMenu/Configure without problem. Why is that?

Does anyone have a suggestion?
12 years ago
If I change my route provider to Plugins/DynamicCategoryMenu/Configure, I can load the page @ http://localhost/Plugins/DynamicCategoryMenu/Configure without problem. Why is that?

I have a lot to learn still, but I believe the page loads without the admin reference because as soon as the "admin/" url is used, the area routing from "Nop.Admin/AdminAreaRegistration.cs" kicks in, sending it looking for controllers in the "Nop.Admin.Controllers" namespace instead of your plugin. Of course I just might be way off on my understanding of how this works. :)

Either way my custom Plugin's RouteProvider is just about identical to the layout of esbee's one, but 7Spikes's solution doesn't seem to be working for me either. Has something changed causing this solution to no longer work?

Thanks
12 years ago
esbee, try changing your custom route to something that uses at least 5 parts.

So instead of

Admin/DynamicCategoryMenu/Configure

Try something like

Admin/Plugin/DynamicCategoryMenu/Admin/Configure

There is a discussion on what I think is the same issue your having over at:

https://www.nopcommerce.com/boards/t/12699/admin-plugin-route.aspx?p=2
8 years ago
Hi Guys,

I am building a plugin in 3.50.
I've added a new menu item, which appends under Plugins menu item by default.
var SubMenuItem = new SiteMapNode()
{
        Title = "Manage",
        ControllerName = "CustomManager",
        ActionName = "List",
        Visible = true,
        RouteValues = new RouteValueDictionary() { { "area", null } },
};
and the routing defined is as
routes.MapRoute("Plugin.Custom.Manager.List",
       "Plugins/CustomManager/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

also tried routing with many ways like

routes.MapRoute("Plugin.Custom.Manager.List",
       "Admin/Plugins/CustomManager/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

routes.MapRoute("Plugin.Custom.Manager.List",
       "Admin/Plugins/CustomManager/Admin/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

I've created the List.cshtml under Views-> CustomManager -> List.cshtml & the controller is named as CustomManagerController.cs

I also added in  List.cshtml
@{
    Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}

But still the url in the browser's generates as http://localhost:15536/CustomManager/List
instead http://localhost:15536/Admin/CustomManager/List
and also once I select my menu item, then some of the link items lose the Admin/ prefix like 'Clear cache', 'Restart application'

Please help me, what I've missed!
8 years ago
danger wrote:
Hi Guys,

I am building a plugin in 3.50.
I've added a new menu item, which appends under Plugins menu item by default.
var SubMenuItem = new SiteMapNode()
{
        Title = "Manage",
        ControllerName = "CustomManager",
        ActionName = "List",
        Visible = true,
        RouteValues = new RouteValueDictionary() { { "area", null } },
};
and the routing defined is as
routes.MapRoute("Plugin.Custom.Manager.List",
       "Plugins/CustomManager/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

also tried routing with many ways like

routes.MapRoute("Plugin.Custom.Manager.List",
       "Admin/Plugins/CustomManager/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

routes.MapRoute("Plugin.Custom.Manager.List",
       "Admin/Plugins/CustomManager/Admin/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

I've created the List.cshtml under Views-> CustomManager -> List.cshtml & the controller is named as CustomManagerController.cs

I also added in  List.cshtml
@{
    Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}

But still the url in the browser's generates as http://localhost:15536/CustomManager/List
instead http://localhost:15536/Admin/CustomManager/List
and also once I select my menu item, then some of the link items lose the Admin/ prefix like 'Clear cache', 'Restart application'

Please help me, what I've missed!


Don't look at RouteProvider.

http://tech.sunnyw.net/2014/01/nopcommerce-register-your-customized.html
8 years ago
sunnyw wrote:

Thank you sunnyw for the response and solution,

I am overriding product view, I just want to override a single partial view '_CreateOrUpdate.Info.cshtml'.
However I did that and loaded data successfully for Product Info tab from my controller of plugin but the rest tabs doesn't loads data with
404 found seems that the routing changes for all.
This is my routing for
var route =
  routes.MapRoute("Plugin.Custom.Manager.Product.Edit.Id",
   "Admin/Product/Edit/{id}",
   new { controller = "Manager", action = "Edit", area = "Admin" },
   new { id = @"\d+" },
   new[] { "Nop.Plugin.Custom.Manager.Controllers" }
);
routes.Remove(route);
routes.Insert(0, route);

and also when I navigate to Catalog -> Products -> Manage Products it removes the Admin/ prefix from 'Clear cache' & 'Restart application'.
This is my routing for Product List
var route =
  routes.MapRoute("Plugin.Custom.Manager.Product.List",
   "Admin/Product/List",
   new { controller = "Manager", action = "List", area = "Admin" },
   new[] { "Nop.Plugin.Custom.Manager.Controllers" }
  );
  
routes.Remove(route);
routes.Insert(1, route);

I am not able to figure out the issue of routing. So can please help me with this?
Thanks in advance.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.