System.InvalidOperationException: IDX20803: Unable to obtain configuration from: ‘System.String’

Just a friendly reminder to myself (and for whom it may concern): This error message tends to appear when the ASP.NET API can’t talk to the IdentityServer.

Especially tricky when using an ASP.NET API and IdentityServer4 behind a reverse proxy (like nginx). The external world might be able to talk to the IdentityServer, but the API server / container might need some additional configuration with the internal host:port of the IdentityServer.

Configure ASP.NET Core ports with Kestrel (Linux)

This is something that I have to google all the time. So let’s write it down as a blog-post! 🙂

The following assumes that we are running ASP.NET Core on Linux, without IIS. Tested with .NET 5

Source: StackOverflow

Options

As dotnet CLI parameter

dotnet YouApp.dll --urls http://localhost:3000

Kestrel-section in appsettings.json

"Kestrel": { 
	"EndPoints": { 
		"Http": { 
			"Url": "http://localhost:3000"
		} 
	} 
}

Environment variable (bash)

export ASPNETCORE_URLS=http://localhost:3000

Environment variable (bash, multiple urls)

export ASPNETCORE_URLS=http://localhost:3000\; https://localhost:3001

(Note: The semicolon has to be escaped with a backslash so it won’t be interpreted by the bash shell)

The list is by no means complete. At this moment I am mostly interested in configuration via environment variables for docker/DevOps/automation scenarios.