Get server URLs in .NET Core 3.1 app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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