Skip to content

Instantly share code, notes, and snippets.

@markrendle
Created April 14, 2020 23:12
Show Gist options
  • Save markrendle/a7eea3b8bcea392291d066ce2f3d4df0 to your computer and use it in GitHub Desktop.
Save markrendle/a7eea3b8bcea392291d066ce2f3d4df0 to your computer and use it in GitHub Desktop.
Get server URLs in .NET Core 3.1 app
public static async Task Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
var task = host.RunAsync();
var serverAddresses = host.Services.GetRequiredService<IServer>()
.Features
.Get<IServerAddressesFeature>();
foreach (var serverAddress in serverAddresses.Addresses)
{
Console.WriteLine(serverAddress);
}
await task;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment