Tushar Tushar - 3 months ago 34
C# Question

Nopcommerce Error- "Page not Found" while redirecting from admin to plugin pages

I am using nopCommerce. I am making plugin Project.

When i tried to redirect Admin page to plugin page,
It gives error like "PAGE NOT FOUND".

My Plugin page url is


localhost:2276/Admin/Category/List


But it works properly for this url


localhost:2276/Plugin/Category/List


RouteProvider.cs

public partial class RouteProvider : IRouteProvider
{
public void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute("Nop.Plugin.Category.ShopByCategory.Views.Category.List",
"Admin/Category/List",
new { controller = "Category", action = "List" },
new[] { "Nop.Plugin.Category.ShopByCategory.Controllers" });
}
public int Priority
{
get { return 0; }
}
}


I need to implement this by this url localhost:2276/Admin/Category/List.
Is there different way to implement this?

Thank you in advance

Answer

If we want to use admin token in URL,we need to add a data token to route.
Here is a code sample how to do this in the RegisterRoutes method of RouteProvider class.

var route = routes.MapRoute(RouteName,
                  "admin/Plugins/PluginName/ControllerName/ActionName",
                  new { controller = "ControllerName", action = "ActionName" },
                  new[] { TheNamespaceOfControllerClass }
             );

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