I am using docker compose file to keep all the environment variables,
environment:
- Instance=https://login.microsoftonline.com/
- ClientId=xxxxxxxx
and I can access these variables in my asp.net core web api app statrtup
class like below,
var instance = Environment.GetEnvironmentVariable("Instance")
var clientId = Environment.GetEnvironmentVariable("ClientId")
In statrtup
class I can send the entire like below IConfiguration
to some method like,
services.AddProtectedWebApi(Configuration);
where it will automatically read all the configuration what I have configured in AzureAd
section of appsettings.json
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"ClientId": "xxxxxxxxxxxxxxxxxxxxxx",
"Domain": "xxxxxxxxxxxxxxxxxxxxxxxxx",
"TenantId": "xxxxxxxxxxxxxxxxxxxxxxx"
},
Now my question is, how we can read environment variables (instead of appsettings.json
) and prepare IConfiguration
with config section AzureAd
?
You should use the following environment variable names with prefix:
environment:
- AzureAd__Instance=https://login.microsoftonline.com/
- AzureAd__ClientId=xxxxxxxx
to override appsettings.json
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.