[英]“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"
)分别重命名为DefaultControllerA
和DefaultControllerB
。
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.