Currently am developing a web application using .net core. To support multiple tenants, I have created multiple web hosts in program.cs like below
public class Program
{
public static async Task Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
var mthost = CreateHostBuilderTest(args).Build();
await Task.WhenAny(host.RunAsync(), mthost.RunAsync());
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<DefaultTenantStartup>();
webBuilder.UseUrls("http://localhost:50001", "https://localhost:50002");
webBuilder.PreferHostingUrls(true);
});
public static IHostBuilder CreateHostBuilderTest(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<SecondTenantStartup>();
webBuilder.UseUrls("http://localhost:50101", "https://localhost:50102");
webBuilder.PreferHostingUrls(true);
});
}
The issue is that the above code works perfectly with kestrel and dotnet command line execution. However, when I host the application in IIS I don't see both the hosts running in parallel. Rather the second one always handles the requests.
Any one tried such things previously?