简体   繁体   English

ASP.Net Core 和 ExtCore.Mvc 库中的“AmbiguousMatchException:请求匹配多个端点”错误

[英]“AmbiguousMatchException: The request matched multiple endpoints” error in ASP.Net Core and ExtCore.Mvc library

I'm using ExtCore.Mvc library and there's a problem when I have 2 controllers with the same name in 2 different extensions.我正在使用 ExtCore.Mvc 库,当我在 2 个不同的扩展中有 2 个具有相同名称的控制器时出现问题。 Here's my code:这是我的代码:

In ExtensionA:在扩展 A 中:

public class UseEndpointsAction : IUseEndpointsAction
{
    public int Priority => 1000;

    public void Execute(IEndpointRouteBuilder endpointRouteBuilder, IServiceProvider serviceProvider)
    {
        endpointRouteBuilder.MapControllerRoute(
            name: "ExtensionA",
            pattern: "ExtensionA",
            defaults: new { controller = "Default", action = "Index" });
    }
}

In ExtensionB:在扩展 B 中:

public class UseEndpointsAction : IUseEndpointsAction
{
    public int Priority => 1000;

    public void Execute(IEndpointRouteBuilder endpointRouteBuilder, IServiceProvider serviceProvider)
    {
        endpointRouteBuilder.MapControllerRoute(
            name: "ExtensionB",
            pattern: "ExtensionB",
            defaults: new { controller = "Default", action = "Index" });
    }
}

There are two controllers as "ExtensionA.Controllers.DefaultController" and "ExtensionB.Controllers.DefaultController".有两个控制器,分别是“ExtensionA.Controllers.DefaultController”和“ExtensionB.Controllers.DefaultController”。

When client requests this URL: "http://{domain}/ExtensionA", it gets the following error:当客户端请求此 URL: "http://{domain}/ExtensionA" 时,会收到以下错误:

An unhandled exception occurred while processing the request.处理请求时发生未处理的异常。 AmbiguousMatchException: The request matched multiple endpoints. AmbiguousMatchException:请求匹配多个端点。 Matches: ExtensionA.Controllers.DefaultController.Index (ExtensionA) ExtensionB.Controllers.DefaultController.Index (ExtensionB)匹配项: ExtensionA.Controllers.DefaultController.Index (ExtensionA) ExtensionB.Controllers.DefaultController.Index (ExtensionB)

I want to solve it using namespace which means to resolve each route to a specific namespace.我想使用命名空间来解决它,这意味着将每个路由解析到特定的命名空间。 I search through the web and I read all MSDN documents yet found nothing.我搜索了 web 并阅读了所有 MSDN 文档但一无所获。 Any help would be appreciated.任何帮助,将不胜感激。

Thanks谢谢

Rename your controllers (and change controller = "Default" ) to DefaultControllerA and DefaultControllerB respectively.将您的控制器(并将controller = "Default" )分别重命名为DefaultControllerADefaultControllerB

Or you can use areas .或者您可以使用区域

Or try implementing some kind of NamespaceConstraintAttribute like was done here .或者尝试实现某种NamespaceConstraintAttribute ,就像在这里完成的那样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:“AmbiguousMatchException:请求匹配多个端点。” - Error: "AmbiguousMatchException: The request matched multiple endpoints." 该请求与 ASP.Net Core OData 中的多个端点匹配 - The request matched multiple endpoints in ASP.Net Core OData AmbiguousMatchException:请求匹配多个端点。 火柴? - AmbiguousMatchException: The request matched multiple endpoints. Matches? 请求匹配 .NET Core 上的多个端点 - The request matched multiple endpoints on .NET Core 如何修复“AmbiguousMatchException:请求匹配多个端点。” - How to fix “AmbiguousMatchException: The request matched multiple endpoints.” 避免ASP.Net Core中的“请求匹配多个操作导致歧义”错误 - Avoiding “Request matched multiple actions resulting in ambiguity” error in ASP.Net Core 具有单个参数的多个 GET() 方法导致 AmbiguousMatchException:请求匹配多个端点 - Multiple GET() methods with a single parameter result in AmbiguousMatchException: The request matched multiple endpoints 启动ASP.NET 5(MVC 6)Web应用程序时出现AmbiguousMatchException - AmbiguousMatchException when starting ASP.NET 5 (MVC 6) Web Application 请求匹配多个操作,导致ASP.NET 5 / MVC 6中具有不同参数的操作不明确 - Request matched multiple actions resulting in ambiguity for actions with different parameters in ASP.NET 5 / MVC 6 如何解决请求与 .Net Core Web Api 中的多个端点匹配的问题 - How do I resolve the issue the request matched multiple endpoints in .Net Core Web Api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM