'Access config vars in Heroku with .NET Core to get the database URL

I deployed a web app with .NET Core 2.2 to Heroku and I want to access the Config Vars to get the database URL. How can I do tha?

Currently, I hardcoded the connection string, but this is only a temporary solution.

The code currently used:

services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(
                    Configuration.GetConnectionString("ExtPostgresConnection")));

Where ExtPostgresConnection is the hardcoded connection string to access the database form outside of Heroku.

Do I need to use Heroku's REST API?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source