The request matched multiple endpoints error while re-routing api endpoints in new plugin

2 недели назад
Hello all,

I have written a new plugin that overrides the Customer-Checkout controllers in nop.web, as well as the customer-checkout controllers in the official plugin (nop.plugin.misc.webapi.frontend). All of the controllers, both in the web and API, have the same methods with the same names and types. I have only overridden the methods that I need to override their input objects, such as the addressadd and addressedit methods in both the web and API controllers.

All of the controllers have area information, and in the routeprovider, I have added every method. The web routings are working fine. I have rerouted the nop.web methods like this:

Class:
[Area("public")]
[ApiExplorerSettings(IgnoreApi = true)]
public partial class CustomerController : Nop.Web.Controllers.CustomerController

Methods:
[HttpPost]
[Route("/Customer/AddressAdd")]
public async Task<IActionResult> AddressAdd(WebCustomerAddressEditModel model, IFormCollection form)

The API controller methods are examples like this:
[Area("frontendapi")]
[ApiExplorerSettings(IgnoreApi = true)]
[Route("/api-frontend/[controller]/[action]")]
public partial class CustomerController : WebApi.Frontend.Controllers.CustomerController

Method example:
[HttpPost]
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(FrontendCustomerAddressEditModelDto), StatusCodes.Status200OK)]
[Route("/api-frontend/Customer/AddressAdd")]
public async Task<IActionResult> AddressAdd([FromBody] BaseModelDtoRequest<FrontendCustomerAddressEditModelDto> request)

However, in the API controllers, the methods that do not have an "override" expression (like the addressadd post method) do not work as expected and throw an error like this:

Error: response status is 500 Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches: Nop.Plugin.Misc.FoDynamicsCrm.Controllers.Api.FrontEnd.CustomerController.AddressAdd (Nop.Plugin.Misc.FoDynamicsCrm) Nop.Plugin.Misc.FoDynamicsCrm.Controllers.Api.FrontEnd.CustomerController.AddressAdd (Nop.Plugin.Misc.FoDynamicsCrm) Nop.Plugin.Misc.WebApi.Frontend.Controllers.CustomerController.AddressAdd (Nop.Plugin.Misc.WebApi.Frontend)

Do you have any suggestions on how to fix this problem?
2 недели назад
mtas wrote:
Hello all,

I have written a new plugin that overrides the Customer-Checkout controllers in nop.web, as well as the customer-checkout controllers in the official plugin (nop.plugin.misc.webapi.frontend). All of the controllers, both in the web and API, have the same methods with the same names and types. I have only overridden the methods that I need to override their input objects, such as the addressadd and addressedit methods in both the web and API controllers.

All of the controllers have area information, and in the routeprovider, I have added every method. The web routings are working fine. I have rerouted the nop.web methods like this:

Class: [Area("public")] [ApiExplorerSettings(IgnoreApi = true)] public partial class CustomerController : Nop.Web.Controllers.CustomerController

Methods: [HttpPost] [Route("/Customer/AddressAdd")] public async Task<IActionResult> AddressAdd(WebCustomerAddressEditModel model, IFormCollection form)

The API controller methods are examples like this: [Area("frontendapi")] [ApiExplorerSettings(IgnoreApi = true)] [Route("/api-frontend/[controller]/[action]")] public partial class CustomerController : WebApi.Frontend.Controllers.CustomerController

Method example: [HttpPost] [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(FrontendCustomerAddressEditModelDto), StatusCodes.Status200OK)] [Route("/api-frontend/Customer/AddressAdd")] public async Task<IActionResult> AddressAdd([FromBody] BaseModelDtoRequest<FrontendCustomerAddressEditModelDto> request)

However, in the API controllers, the methods that do not have an "override" expression (like the addressadd post method) do not work as expected and throw an error like this:

Error: response status is 500 Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches: Nop.Plugin.Misc.FoDynamicsCrm.Controllers.Api.FrontEnd.CustomerController.AddressAdd (Nop.Plugin.Misc.FoDynamicsCrm) Nop.Plugin.Misc.FoDynamicsCrm.Controllers.Api.FrontEnd.CustomerController.AddressAdd (Nop.Plugin.Misc.FoDynamicsCrm) Nop.Plugin.Misc.WebApi.Frontend.Controllers.CustomerController.AddressAdd (Nop.Plugin.Misc.WebApi.Frontend)

Do you have any suggestions on how to fix this problem?


Can you able for code? is required
2 недели назад
I fixed this problem by adding a Route with an order value to my controller class like this.

    [Area("frontendapi")]
    [ApiExplorerSettings(IgnoreApi = true)]
    [Route("/api-frontend/[controller]/[action]", Order = int.MaxValue - 1)]
    public partial class CustomerController : WebApi.Frontend.Controllers.CustomerController

Inherited base controller is like this in api plugin source code.
    [ProducesResponseType(typeof(string), StatusCodes.Status401Unauthorized)]
    [Area("api-frontend")]
    [Route("api-frontend/[controller]/[action]", Order = int.MaxValue)]
    [ApiExplorerSettings(GroupName = "frontend_" + WebApiCommonDefaults.API_VERSION)]
    public abstract class BaseNopWebApiFrontendController : BaseNopWebApiController
    {
    }

Its now working as expected but how it is working I don't understand :)