Register route to plugin with 4.1

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
I'm using nopCommerce v4.1.

I created a new plugin and registered a new route like described here.

The problem is that the route only reaches the controllers within the Nop.Web project and not within my new plugin.
How can I register a new route to my plugin?

I want that all my views within the plugin can be reached by e.g. www.store.com/custom/customview
5 years ago
Your problem might be addressed in this blog (i saved it for future use some time ago)
http://tech.sunnyw.net/2013/11/nopcommerce-customization-with.html

however 4.1 is rewritten for ASP.NET Core and I suppose the routing is brand new in the Core version, so this might not help you.  I have not yet seen 4.1 or much Core code from the inside, so sorry if it doesn't help.
5 years ago
public partial class RouteProvider : IRouteProvider
    {
        public void RegisterRoutes(IRouteBuilder routeBuilder)
        {
             routeBuilder.MapRoute("Plugin.Payments.PayPalStandard.PDTHandler", "Plugins/PaymentPayPalStandard/PDTHandler",
             new { controller = "PaymentPayPalStandard", action = "PDTHandler" });
        }
        public int Priority
        {
            get
            {
                return -1;
            }
        }
    }


from documentation.
5 years ago
It didn't work for me :(

My Route Provider:


using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Nop.Web.Framework.Mvc.Routing;

namespace Nop.Plugin.Locator.StoreLocator.Infrastructure
{
    public partial class RouteProvider : IRouteProvider
    {
        /// <summary>
        /// Register routes
        /// </summary>
        /// <param name="routeBuilder">Route builder</param>
        public void RegisterRoutes(IRouteBuilder routeBuilder)
        {

            routeBuilder.MapRoute("Plugin.Locator.StoreLocator.Stores", "stores",
             new { controller = "StoreLocator", action = "Stores" });

        }

        /// <summary>
        /// Gets a priority of route provider
        /// </summary>
        public int Priority
        {
            get { return 1001; }
        }
    }
}


My Controller


namespace Nop.Plugin.Locator.StoreLocator.Controllers
{



public IActionResult Stores()
        {
            var model = new ConfigurationModel();


            return View("~/Plugins/Locator.StoreLocator/Views/Stores.cshtml", model);
        }


Whenever I try to open http://localhost:xxxx/stores receiving Page not found.
5 years ago
When I changed it to


routeBuilder.MapRoute("Plugin.Locator.StoreLocator.Stores", "Plugins/StoreLocator/Stores/",
             new { controller = "StoreLocator", action = "Stores" });


it works fine on admin side
5 years ago
How can we register a route to view on frontend?
5 years ago
EverydayXpert wrote:
I'm using nopCommerce v4.1.

I created a new plugin and registered a new route like described here.

The problem is that the route only reaches the controllers within the Nop.Web project and not within my new plugin.
How can I register a new route to my plugin?

I want that all my views within the plugin can be reached by e.g. www.store.com/custom/customview


Ok, it took me while to figure it out;

Create a new controller as base controller


public class FrontEndController: BaseController


Add your method

#region Methods
        public IActionResult Customview()
        {
            var model = new ConfigurationModel
            {
                xx = _storeLocatorSettings.xxx
            };


            return View("~/Plugins/Your Plugin/Views/customview.cshtml", model);
        }
        #endregion


then in your route provider


routeBuilder.MapRoute("Plugin.Your Plugin.Customview", "custom/customview",
             new { controller = "FrontEnd", action = "Customview" });


and it works
4 years ago
[SOLVED] I was also able to get this to work by creating a new controller.  I realized something as I did, my first controller that I created by copying examples, for admin configuration, has these attributes:

    [AuthorizeAdmin]
    [Area(AreaNames.Admin)]

I think these were preventing my original controller (created for the configuration actions) from also being able to support non-admin access.
3 years ago
EverydayXpert wrote:
I'm using nopCommerce v4.1.

I created a new plugin and registered a new route like described here.

The problem is that the route only reaches the controllers within the Nop.Web project and not within my new plugin.
How can I register a new route to my plugin?

I want that all my views within the plugin can be reached by e.g. www.store.com/custom/customview


have you got any sollution yet?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.