I want build a solution with two listening entrypoints with partly the same paths but different purposes and responses. Therefore I've followed the introductions on https://khalidabuhakmeh.com/hosting-two-aspnet-core-apps-in-one-host strictly - used different ports for both "startups" and so on. Unfortunately the running environment fails by calling a double existing path with an appropriate port. The startup file, controllers and further configuration of the second entrypoint are in an additional project.
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
public static IHostBuilder CreateSecondBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseUrls("http://*:5500").UseStartup<SecondEndpoint.Startup>();
});
The error message is
Connection id "xxx",, Request id "xxx": An unhandled exception was thrown by the application. Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches: Controllers.FruitsController.GetFruits (...) SecondEndpoint.Controllers.FruitsController.GetFruits (...)
In my opinion, the fault is that
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
maps all Controllers of all referenced projects. Is their a possibility to ajust the mapping of some controllers to a specific entrypoint? Thanks for an advise!