SmnHgr
SmnHgr

Reputation: 107

Hosting Two ASP.NET Core Apps In One Host With Same Paths

I want build a solution with two listening entry points 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 entry point 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 adjust the mapping of some controllers to a specific entr ypoint?

Upvotes: 1

Views: 1559

Answers (1)

CodingMytra
CodingMytra

Reputation: 2600

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.

Upvotes: -1

Related Questions