NOP 4.3: Plugin route is not working for [HttpPost]

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 年 前
The route is working for GET but not for POST.
Here is my code:

RouteProvider.cs:

 public partial class RouteProvider : IRouteProvider
    {      
        public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
        {                        
endpointRouteBuilder.MapControllerRoute("Plugin.Payments.Tranzila.SetTransactionStatus", "Plugins/PaymentTranzila/SetTransactionStatus",
                 new { controller = "PaymentTranzila", action = "Test1" });


endpointRouteBuilder.MapControllerRoute("Plugin.Payments.Tranzila.SetTransactionStatus", "Plugins/PaymentTranzila/Test",
                new { controller = "PaymentTranzila", action = "Test" });
        }
      
        public int Priority => -1;
    }



Controller:

      
 [HttpPost]
        public IActionResult Test1()
        {            
            return null;
        }

        public IActionResult Test()
        {
            return null;
        }
3 年 前
The problem was:  [AutoValidateAntiforgeryToken]
3 年 前
Hi, Can you explain what's the problem and the solution?
I have the same problem with the callback Action method in the payment plugin in NopCommerce 4.0 (Bank redirect User with post method to call back URL and post some values). when I use [HttpPost] routing not found my action and when to remove that, my action is called but form values are null.
I test some attributes but routing is not found my action yet.
       //[HttpPost]
       //[AutoValidateAntiforgeryToken]
       //[AdminAntiForgery(true)]
        public ActionResult CallBack(IFormCollection form)
        {....
3 年 前
This is how I did it:

My plugin controller:

        
        [HttpPost]
        public IActionResult PaymentSuccess() {
            var paymentIndex= Request.Form["paymentIndex"];
       }
        


My RouteProvider.cs:
      public void RegisterRoutes(IRouteBuilder routeBuilder)
        {

            routeBuilder.MapRoute("Plugin.Payments.Tranzila.PaymentSuccess", "Plugins/PaymentTranzila/PaymentSuccess",
                new { controller = "PaymentTranzila", action = "PaymentSuccess" });


I am not using
[AutoValidateAntiforgeryToken]
3 年 前
Thank you for sharing this.
3 年 前
With pleasure mate :)
please let me know if I can be of any further help
2 年 前
if plugin route not wotking that means is not an issue with below filter
[AutoValidateAntiforgeryToken]

we can call our action method using route with [AutoValidateAntiforgeryToken]

solution :

if we want to call a route in 4.3 and we are using a form tag in html page using  below this with post method
<form asp-route="Myroute" method="post">

instead of using this we need to use and call with controller/action and paramenter.

<form asp-controller="MyController" asp-action="MyAction" asp-route-Id="@Model.Id" method="post">

It will call our route method using routeprovider and we will get the result with route url
for custom action method...
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.