ASP.net core may run on arbitrary number of ports, sometimes the application may run via command line getting passed port as a parameter, sometimes within docker it's running at 80
if profile Released
is specified, how can we determine programmatically what port asp.net is actually running on?
A suggested answer is not an answer because that requires access to context and let's say on Startup
I need to access this value?
launchSettings.json
"Customer": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "https://localhost:5007;http://localhost:5006",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
}
for instance, in the following code
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Service>();
or anywhere during the system startup process.