I have a ASP.NET Core 2.0 web application, where I need to pass the application's URL out during startup for the purposes of integration into something else.
When running under Visual Studio (IIS Express), IApplicationBuilder.ServerFeatures.Get<IServerAddressesFeature>().Addresses
contains the URL my application is bound to (e.g. http://localhost:1234
).
When run using dotnet.exe myapp.dll
, the same collection is empty, however, I get a line on stdout saying Now listening on: http://localhost:5000
.
The question is, to get the URL, do I have to parse the output of dotnet.exe for the line beginning Now listening on:
, or is there a less fragile way?