Determine port Kestrel binded to
问题 I'm writing a simple ASP.NET Core service using ASP.NET Core empty ( web ) template. By default, it binds to port 5000 but I would like it to bind to a random available port on the system. I can do so by modifying BuildWebHost to: public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseUrls("http://*:0") // This enables binding to random port .Build(); It binds to a random port but how do I determine from within the application which