Plugin and RouteProvider

Posted: September 20, 2011 at 8:58 AM Quote #49373
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
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: September 26, 2011 at 2:58 AM Quote #49845
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!
This post/answer is useful
6
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
www.Nop-Templates.com - the best place for nopCommerce themes and plugins

Follow us on
Facebook: http://www.facebook.com/NopTemplates
Twitter: http://twitter.com/NopTemplates
Blog: http://www.nop-templates.com/blog

www.7Spikes.com
nopCommerce Solution Partners
Posted: September 26, 2011 at 8:18 AM Quote #49865
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
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: October 12, 2011 at 8:16 PM Quote #51412
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?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
http://www.gsi-alarme-securite.com
http://www.securibay.com
Posted: October 26, 2011 at 1:40 AM Quote #52703
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
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: October 26, 2011 at 12:45 PM Quote #52789
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:

http://www.nopcommerce.com/boards/t/12699/admin-plugin-route.aspx?p=2
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
nopCommerce on facebook