Routing not working in new Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
I'm working on a new plugin for NopCommerce 4 but I keep getting a page not found error when I try to go to the URL of my acton method.

I compiled and installed my plugin already and the table was created however I cannot view the view from my Action method, please help!

My Plugin should return a list of Objects when a product Id is given to it. Here are some details of my configuration:
Namespace: Nop.Plugin.Misc.TPReviews
Path to project: Plugins\Nop.Plugin.Misc.TPReviews
Path to Compiled DLL: root\Plugins\TPReviews
Controller: Nop.Plugin.Misc.TPReviews.Controllers.GetReviews
Route:
routes.MapRoute("Nop.Plugin.Misc.TPReviews",
                 "Plugins/TPReviews/GetReviews/",
                 new { controller = "GetReviews", action = "Index" },
                 new[] { "Nop.Plugin.Misc.TPReviews.Controllers" });

WHere I browse to /plugin/tpreviews/getreviews?Id=16722 I get the NopCommerce 404 page
4 years ago
Did you follow this guide ?
https://docs.nopcommerce.com/developer/plugins/how-to-write-plugin_4.20.html
4 years ago
Thanks. I followed this one: https://docs.nopcommerce.com/developer/plugins/how-to-write-plugin_4.00.html
as I'm on 4.0.
Still it does not work.
4 years ago
Have you defined the area attribute in the plugin's controller? The guide asks to define the area. But you only need the area attribute for the admin portal. If you want the route to be visible in public portal then you should remove the
[Area(AreaNames.Admin)]
attribute
4 years ago
Did you work out the problem ? I was having a similar issue
I installed this https://github.com/kobake/AspNetCore.RouteAnalyzer in the Framework and I found that the route was being setup differently to what I defined
4 years ago
sanju.dahal741 wrote:
Have you defined the area attribute in the plugin's controller? The guide asks to define the area. But you only need the area attribute for the admin portal. If you want the route to be visible in public portal then you should remove the
[Area(AreaNames.Admin)]
attribute


No, I did not include the area attribute as I need it to be public.
Any other things to check?  I really appreciate you looking into this.
4 years ago
Yidna wrote:
Did you work out the problem ? I was having a similar issue
I installed this https://github.com/kobake/AspNetCore.RouteAnalyzer in the Framework and I found that the route was being setup differently to what I defined


I tried to install it on my plugin project and got the following error:  "Install-Package : Could not install package 'Microsoft.AspNetCore 2.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.1', but the package does not contain any assembly references or content files that are compatible with that framework."

Do I have to install it on the main NopCommerce.Web Project instead?  Is the error an indication of a problem on my plugin?

Thanks!
4 years ago
Well, this may sound like a silly suggestion.
But I have run into the similar problems in my past when I was trying to access the route of the plugin before I have installed the plugin. Can you verify that the plugin has been installed successfully in the /Admin/Plugin/List page?
4 years ago
sanju.dahal741 wrote:
Well, this may sound like a silly suggestion.
But I have run into the similar problems in my past when I was trying to access the route of the plugin before I have installed the plugin. Can you verify that the plugin has been installed successfully in the /Admin/Plugin/List page?


Yes, It's listed as installed.  It created the Database table too.  I also tried uninstall and reinstall and the table was dropped and recreated.

I also put a break point in RouteProvider.cs, I see the route being added to the system (as number 180) and it seems correct according to what I planned.  But it still does not find the controller when I go to the URL.
4 years ago
Hello,

There are several things you could check:

Is your controller a public class?
Is your method (the Index endpoint) a public method? Actually, could you share the method signature with us so we can see if there is anything wrong with that also?
You could try to remove the namespace parameter when you are registering the route.
Also, try to call your method without the Id parameter so you could see if that is causing an issue.

Hope that helps!

Regards,
Anton
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.