✅ How to setup environment variables in Azure Web App
I've deployed my Blazor Server App to Azure Web App. And in App settings I've added some items e.g my Cloudinary URL and in Connection Strings section I've made a connection string named as "DefaultConnection" same as it was in my appsettings.json file. However I'm getting some Postgress EFCore error in production.
Here's my Program.cs:
https://paste.mod.gg/ltvubhnjcema/0
My appsettings.json structure:
AI told me that the environment variables I set are supposed to override these values but apparently they aren't and I'm not sure how to check. Can someone guide me the correct way to do it. Thanks
12 Replies
How did you define the env variables?
There's a common issue with separators
To quote from the docs:
In a default Linux app service or a custom Linux container, any nested JSON key structure in the app setting name needs to be configured differently for the key name. Replace any colon (:) with a double underscore (). Replace any period (.) with a single underscore (_). For example, ApplicationInsights:InstrumentationKey needs to be configured in App Service as ApplicationInsightsInstrumentationKey for the key name.
This is how Envs are defined

Connection String

Configure an App Service App - Azure App Service
Learn how to configure common settings for an Azure App Service app. You can use the Azure portal, Azure CLI, or Azure PowerShell.
This states the connection strings are accessible with a specific prefix at runtime
To be fair I never really used the connection strings config option for azure web apps
I just use env vars, I don't like the implicit conventions for the most part
Oh thanks for sharing that guide, I'll try it tomorrow and will let ya know
That prefix thing might do it , hopefully
you had it correct,
would look like the screenshot in Azure

I do get weird issues by choosing a specific connection string type though often, so usually just choose Custom as the type
I'll try custom type. How do you Access it in your Program.cs? Just like normal or with prefix

builder.Configuration.GetConnectionString("DefaultConnection")
Alright, thanks
@Zaneris @Sossenbinder tysm, I just changed my connection string type to "Custom" and apparently it has started working. God bless ya