0

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!

SmnHgr
  • 57
  • 1
  • 4

1 Answers1

1

I was able to solve this issue by using solution given in this link.

Check this Add/Skip ApiController for Web API in .Net Core

essentially you have to map only the required controller for each startup class in configure service method.

CodingMytra
  • 2,234
  • 1
  • 9
  • 21
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 18 '22 at 23:02