Can't overwrite route even with a higher priority

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hi want to overwrite the route to AddProductToCart-Details So I can use my custom controller and methods But I can't seem to let it work even with a higher priority set I still get the message a route with the same name already has been registered.

Can someone help me out?

This is the code I've been using:

using System.Web.Mvc;
using System.Web.Routing;
using Nop.Web.Framework.Mvc.Routes;
using Nop.Plugin.Misc.FurnitureConfigurator.Infrastructure;
using Nop.Web.Framework.Localization;
using System.Web;

namespace Nop.Plugin.Misc.FurnitureConfigurator
{
    public partial class RouteProvider : IRouteProvider{

        public void RegisterRoutes(RouteCollection routes){

            routes.MapLocalizedRoute("AddProductToCart-Details",
                "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                new { controller = "U14SCController", action = "AddProductToCart_Details" },
                new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                new[] { " Nop.Plugin.Misc.FurnitureConfigurator.Controllers" });

            System.Web.Mvc.ViewEngines.Engines.Add(new ViewEngine());

        }
        public int Priority
        {
            get
            {
                return 2147483647;
            }
        }
    }
}
6 years ago
NopDevelop2017 wrote:
Hi want to overwrite the route to AddProductToCart-Details So I can use my custom controller and methods But I can't seem to let it work even with a higher priority set I still get the message a route with the same name already has been registered.

Can someone help me out?

This is the code I've been using:

using System.Web.Mvc;
using System.Web.Routing;
using Nop.Web.Framework.Mvc.Routes;
using Nop.Plugin.Misc.FurnitureConfigurator.Infrastructure;
using Nop.Web.Framework.Localization;
using System.Web;

namespace Nop.Plugin.Misc.FurnitureConfigurator
{
    public partial class RouteProvider : IRouteProvider{

        public void RegisterRoutes(RouteCollection routes){

            routes.MapLocalizedRoute("AddProductToCart-Details",
                "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                new { controller = "U14SCController", action = "AddProductToCart_Details" },
                new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                new[] { " Nop.Plugin.Misc.FurnitureConfigurator.Controllers" });

            System.Web.Mvc.ViewEngines.Engines.Add(new ViewEngine());

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


You have to put new name of "AddProductToCart-Details" i.e ==>"CustomAddProductToCart-Details" And you also did wrong on Controller Name


  routes.MapLocalizedRoute("CustomAddProductToCart-Details",
                "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                new { controller = "U14SC", action = "AddProductToCart_Details" },
                new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                new[] { " Nop.Plugin.Misc.FurnitureConfigurator.Controllers" });
6 years ago
sohel wrote:
Hi want to overwrite the route to AddProductToCart-Details So I can use my custom controller and methods But I can't seem to let it work even with a higher priority set I still get the message a route with the same name already has been registered.

Can someone help me out?

This is the code I've been using:

using System.Web.Mvc;
using System.Web.Routing;
using Nop.Web.Framework.Mvc.Routes;
using Nop.Plugin.Misc.FurnitureConfigurator.Infrastructure;
using Nop.Web.Framework.Localization;
using System.Web;

namespace Nop.Plugin.Misc.FurnitureConfigurator
{
    public partial class RouteProvider : IRouteProvider{

        public void RegisterRoutes(RouteCollection routes){

            routes.MapLocalizedRoute("AddProductToCart-Details",
                "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                new { controller = "U14SCController", action = "AddProductToCart_Details" },
                new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                new[] { " Nop.Plugin.Misc.FurnitureConfigurator.Controllers" });

            System.Web.Mvc.ViewEngines.Engines.Add(new ViewEngine());

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

You have to put new name of "AddProductToCart-Details" i.e ==>"CustomAddProductToCart-Details" And you also did wrong on Controller Name


  routes.MapLocalizedRoute("CustomAddProductToCart-Details",
                "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                new { controller = "U14SC", action = "AddProductToCart_Details" },
                new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                new[] { " Nop.Plugin.Misc.FurnitureConfigurator.Controllers" });



I want (for example) when the route "AddProductToCart-Details" get's triggered my custom method get's triggered instead of the the default one. That's why I assumed that the name should be the same because that way only the route has to be changed and not every element in every view that is calling the route "AddProductToCart-Details". But it seems like you said that isn't possible. So I'll go for using a different name and changing the views.. Thanks for the support Sohel
6 years ago
NopDevelop2017 wrote:
Hi want to overwrite the route to AddProductToCart-Details So I can use my custom controller and methods But I can't seem to let it work even with a higher priority set I still get the message a route with the same name already has been registered.

Can someone help me out?

This is the code I've been using:

using System.Web.Mvc;
using System.Web.Routing;
using Nop.Web.Framework.Mvc.Routes;
using Nop.Plugin.Misc.FurnitureConfigurator.Infrastructure;
using Nop.Web.Framework.Localization;
using System.Web;

namespace Nop.Plugin.Misc.FurnitureConfigurator
{
    public partial class RouteProvider : IRouteProvider{

        public void RegisterRoutes(RouteCollection routes){

            routes.MapLocalizedRoute("AddProductToCart-Details",
                "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                new { controller = "U14SCController", action = "AddProductToCart_Details" },
                new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                new[] { " Nop.Plugin.Misc.FurnitureConfigurator.Controllers" });

            System.Web.Mvc.ViewEngines.Engines.Add(new ViewEngine());

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

You have to put new name of "AddProductToCart-Details" i.e ==>"CustomAddProductToCart-Details" And you also did wrong on Controller Name


  routes.MapLocalizedRoute("CustomAddProductToCart-Details",
                "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                new { controller = "U14SC", action = "AddProductToCart_Details" },
                new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                new[] { " Nop.Plugin.Misc.FurnitureConfigurator.Controllers" });



I want (for example) when the route "AddProductToCart-Details" get's triggered my custom method get's triggered instead of the the default one. That's why I assumed that the name should be the same because that way only the route has to be changed and not every element in every view that is calling the route "AddProductToCart-Details". But it seems like you said that isn't possible. So I'll go for using a different name and changing the views.. Thanks for the support Sohel


I think you misunderstand ==> You only keep unique route name but the url will same  "addproducttocart/details/{productId}/{shoppingCartTypeId}"
6 years ago
sohel wrote:

I think you misunderstand ==> You only keep unique route name but the url will same  "addproducttocart/details/{productId}/{shoppingCartTypeId}"


Ok I get that but the route gets called by the naming right? For example this element underneath passes the name which the RouteUrl method looks up and points it in the right direction.

<input type="button" id="[email protected]" class="button-1 add-to-cart-button" value="@addToCartText" data-productid="@Model.ProductId" onclick="AjaxCart.addproducttocart_details('@Url.RouteUrl("AddProductToCart-Details", new { productId = Model.ProductId, shoppingCartTypeId = (int)ShoppingCartType.ShoppingCart })', '#product-details-form');return false;" />

If I want this element to call my custom method I must let it call the custom name right?
<input type="button" id="[email protected]" class="button-1 add-to-cart-button" value="@addToCartText" data-productid="@Model.ProductId" onclick="AjaxCart.addproducttocart_details('@Url.RouteUrl("CustomAddProductToCart-Details", new { productId = Model.ProductId, shoppingCartTypeId = (int)ShoppingCartType.ShoppingCart })', '#product-details-form');return false;" />

If this is true I have to register a custom route to my custom method and change every element in a view that calls the name "AddProductToCart-Details" in stead of just changing the default route to my custom method
6 years ago
NopDevelop2017 wrote:

I think you misunderstand ==> You only keep unique route name but the url will same  "addproducttocart/details/{productId}/{shoppingCartTypeId}"

Ok I get that but the route gets called by the naming right? For example this element underneath passes the name which the RouteUrl method looks up and points it in the right direction.

<input type="button" id="[email protected]" class="button-1 add-to-cart-button" value="@addToCartText" data-productid="@Model.ProductId" onclick="AjaxCart.addproducttocart_details('@Url.RouteUrl("AddProductToCart-Details", new { productId = Model.ProductId, shoppingCartTypeId = (int)ShoppingCartType.ShoppingCart })', '#product-details-form');return false;" />

If I want this element to call my custom method I must let it call the custom name right?
<input type="button" id="[email protected]" class="button-1 add-to-cart-button" value="@addToCartText" data-productid="@Model.ProductId" onclick="AjaxCart.addproducttocart_details('@Url.RouteUrl("CustomAddProductToCart-Details", new { productId = Model.ProductId, shoppingCartTypeId = (int)ShoppingCartType.ShoppingCart })', '#product-details-form');return false;" />

If this is true I have to register a custom route to my custom method and change every element in a view that calls the name "AddProductToCart-Details" in stead of just changing the default route to my custom method




You can delete the route from the rout table collection and can add your one like bellow then you do not need to change any markup



            
routes.Remove(routes["AddProductToCart-Details"]);

            routes.MapLocalizedRoute("AddProductToCart-Details",
                      "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                      new { controller = "YourPluginControllerName", action = "AddProductToCart_Details" },
                      new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                      new[] { "Nop.Plugin.Misc.YourPlugin.Controllers" });
6 years ago
sina.islam wrote:

You can delete the route from the rout table collection and can add your one like bellow then you do not need to change any markup

            
routes.Remove(routes["AddProductToCart-Details"]);

            routes.MapLocalizedRoute("AddProductToCart-Details",
                      "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                      new { controller = "YourPluginControllerName", action = "AddProductToCart_Details" },
                      new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                      new[] { "Nop.Plugin.Misc.YourPlugin.Controllers" });


I've tried that before but doesn't work. I guess the default routes get added at the end? To bad I can't overrule a route. Is there no cleaner way to do this?
6 years ago
sina.islam wrote:

You can delete the route from the rout table collection and can add your one like bellow then you do not need to change any markup

            
routes.Remove(routes["AddProductToCart-Details"]);

            routes.MapLocalizedRoute("AddProductToCart-Details",
                      "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                      new { controller = "YourPluginControllerName", action = "AddProductToCart_Details" },
                      new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                      new[] { "Nop.Plugin.Misc.YourPlugin.Controllers" });


I've tried that before but doesn't work. I guess the default routes get added at the end? To bad I can't overrule a route.

Is there no cleaner way to do this?
6 years ago
NopDevelop2017 wrote:

You can delete the route from the rout table collection and can add your one like bellow then you do not need to change any markup

            
routes.Remove(routes["AddProductToCart-Details"]);

            routes.MapLocalizedRoute("AddProductToCart-Details",
                      "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                      new { controller = "YourPluginControllerName", action = "AddProductToCart_Details" },
                      new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                      new[] { "Nop.Plugin.Misc.YourPlugin.Controllers" });


I've tried that before but doesn't work. I guess the default routes get added at the end? To bad I can't overrule a route.

Is there no cleaner way to do this?



It is tested and working.After all it is a collection so we can remove its element.
6 years ago
sina.islam wrote:

It is tested and working.After all it is a collection so we can remove its element.

I've tried it and it doesn't work I checked if the route with the  name "AddProductToCart-Details" was present in the collecction before deleting it which it wasn't so yeah sure I can delete it but if nopcommerce adds it after I add mine there will always be a fault.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.