This is a continuation of this issue.
Find 2 different FREE ports for 2 kestrel servers
I was able to start 2 kestrel servers from Console app using dynamic ports and on some computers it works fine, but sometimes this approach fails.
TLDR
- Kestrel should create HTTP and HTTPS connection, but creates only HTTP
- Even when it says that HTTP connection was created it's not reachable
For testing purposes, I created Firewall rule that opens all ports for all protocols and all apps, and then completely disabled Firewall itself. For clarity, I'm not using IIS and start Kestrel manually from C# Console application as local server.
Issues
- Code in the link above should create HTTPS connection for each server, but on Windows Server 2012 and some Windows 10 Pro computers it creates only HTTP connection, although having HTTPS is not critical in this case if I knew how to solve another problem below. I think, it's because some update in Windows may require all HTTPS connections to have SSL certificate and as far as I don't provide it, server doesn't even try to create HTTPS connection. Is there a settings in Kestrel to ignore SSL certificate validation for localhost?
public static IWebHost Run<T>(ServerOptions options = null) where T : class
{
var configuration = new ConfigurationBuilder().Build();
var urls = new[]
{
"http://0.0.0.0:0",
"https://0.0.0.0:0"
};
var environment = WebHost
.CreateDefaultBuilder(new string[0])
.ConfigureServices(o => o.AddSingleton(options))
.UseConfiguration(configuration)
.UseUrls(urls)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseKestrel()
//.UseIISIntegration()
.UseStartup<T>()
.Build();
environment.RunAsync();
return environment;
}
// Issue #1
// On some computers
// webAddresses = ["http://0.0.0.0:50210", "https://0.0.0.0:50220"]
// On other computers and even for 2 users on the same Windows server it doesn't create HTTPS
// webAddresses = ["http://0.0.0.0:50210"]
var webEnvironment = Server.Run<Startup>();
var webAddresses = webEnvironment.ServerFeatures.Get<IServerAddressesFeature>().Addresses;
- Second issue is that on some computers the code gets executed without any error or exception and returns dynamic address for the server, e.g. http://0.0.0.0:50210 but when I try address http://127.0.0.1:50210 in a browser, it says that website cannot be reached and connection to this server was actively refused. I would blame some incompatibility issues with Windows Server 2012 and Windows 8 and Kestrel, but I have Windows 10 VPS where this app works fine for one system user and cannot create HTTPS for another one and the only difference between those users is that I modified NETSH rules for one of them. I could probably create BAT script trying to open all ports for all users and that would allow my app with dynamic ports to function as expected, but maybe there is some Kestrel settings that would make application available on dynamic port without raping Firewall and network settings?