I\'ve got an ASP.NET Core 2.0 app which I intend to run as a stand-alone application. The app should start up and bind to an available port. To achieve this I configure the
At least from .Net Core 3 you can inject IServer and get the information.
using System;
using System.Linq;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
namespace MyApp.Controllers
{
public class ServerInfoController : Controller
{
public ServerInfoController (IServer server)
{
var addresses = server.Features.Get()?.Addresses?.ToArray();
}
}
}