I'm learning how to work with in ASP.NET Core 2 and I've come across a rather annoying problem. Whenever I run my application, the Kestrel server ignores my endpoint configuration and instead starts listening on a random port. Needless to say, this is not the behavior I expected. When digging through the server logs I also came upon this message:
Overriding endpoints defined in UseKestrel() because PreferHostingUrls is set to true. Binding to address(es) 'http://localhost:<some random port>' instead.
I have so far been unable to find any documentation on this "PreferHostingUrls" setting or how to change it. Does anyone know how i can configure Kestrel to listen on the specified port instead of a random one?
My host configuration looks like this:
WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.UseKestrel(
options =>
{
options.Listen(IPAddress.Loopback, 50734);
options.Listen(IPAddress.Loopback, 44321, listenOptions =>
{
listenOptions.UseHttps("pidea-dev-certificate.pfx", "****************");
});
})
.UseStartup<Startup>()
.UseIISIntegration()
.Build();