I have created windows forms application in .netcore 3.1 , that host two WEB Api services, using WebHostBuilder
from the framework dependence of AspNetCore 3.1. (one on port 5000, one on 5001).
I have also created two ApiControllers, with annotations:
[Route("api/[controller]")]
[ApiController]
And the second one:
[Route("api2/[controller]")]
[ApiController]
In both Startup classes, I am setting:
services.AddControllers();
and later:
endpoints.MapControllers()
And it works like a charm.
Now I want to the first controller to be accessible only to port 5000, and the second only to 5001. And the runtime is adding both of them, to the both WEB Api.
So for example:
First Api (at port 5000)
...:5000/api/ - works!
...:5000/api2/ - 404!
Second Api (at port 5001)
...:5001/api/ - 404!
...:5001/api2/ - works!
Is there a way to register specific controller to specific WEB Api, instead of adding everything that is inside your project?
For example, add only controllers, that start with route "api/" or any in specific namespace, or ...any way whatsoever...