Issue with configuring Umbraco from Azure App Conf...
# help-with-umbraco
d
Good morning, I am having a very strange issue with Umbraco. we have recently made a push to move our configuration out of app settings and into azure app configuration and key vault for secrets. I have set up a dev environment that has the usual local dev settings that everyone in my team can use. the connection string for Umbraco db is now stored there. when the conn string is in the old appsettings it works fine but when it's only from the azure provider it asks me to install Umbraco db. usual conn string for local development Server=.;Database=DbName;User Id=sa;Password=PasswordHere;MultipleActiveResultSets=true;TrustServerCertificate=True debugging I can see the config provider fine. I can see it being used in the AddUmbraco() extension when I debug it (Downloaded the source code and pointed to it instead of the nuget to get the symbols etc). However when it goes into the AddBackOffice() extension it seems to be pulling in a completely different IConfiguration. I'm not sure where it's coming from and it only contains the appsettings.json, and not my azure one that i passed into the original builder. can anyone advice if there's some way to force it to use the configuration I provided?
k
This works completely automatically for us with the ootb Umbraco project template. Order of configuration is Azure environment variables > ASPNETCORE_ENVIRONMENT-specific appSettings > appSettings. Did you make any modifications to the ootb template? What does "my azure one that i passed into the original builder" mean?
d
So this is where i'm passing in the configuration. you can see the provider for AzureAppConfiguration which has my conn string in it https://cdn.discordapp.com/attachments/1260506916623355926/1260524334653378631/0.png?ex=668fa244&is=668e50c4&hm=78446bc7136f2a15c0f05693c40974e5f45ace0ef0a0ac29783459130bd69179&
when debugging the AddUmbraco(_env, _config) i can see that it is using this fine
But when it goes into the .AddbackOffice() and gets to the same bit of code again it has completly different IConfiguration
I have no idea where it's pulling in that second iconfiguration from as i'm not setting or providing it
s
it first looks in appSetttings.Development.json and then appSettings.json - so if a connection string is specified there it will take that one.
It also looks in windows secrets first, in case that one is set
d
Yes. so when i put the conn string back into the appsettings it works perfectly. but when it's not there it doesn't seem to like getting it from my azure app configuration.
s
Don't really know how to set that up, but doesn't it read what azure app configuration to use from the appSettings file as well?
d
it's especialy strange as stepping into it i can see it works the first time when inside the AddUmbraco() extension but when it gets to the addBackOffice() it seems to have a different set of config providers
s
If you only put that in your appSettings.Production.json file then it doesn't know to use it
d
I'm not sure i follow sorry. the config for azure app configuration is in the appsettings.json if that's what you mean
when debuging i can see that that has worked and the secret is available via that provider
s
yeah okay that seems fine then! In which case.. no idea, sorry
d
Yeah it's a real mystery
s
what happens if you install Umbraco when asked on local? which database does it use?
d
If i point it to the db seems to do the install but next time i try to run it same issue.
it seems to be unable to find the sql on startup. which makes sense from what i've seen stepping through the code etc
s
Yeah if there's no connection string then it will ask what database to use, that makes sense. But then it should update the appsettings file and run from the same db the next time though.
k
I'm still wondering if you made any changes to the ootb
Program.cs
since this usually works automatically 🙂
d
no changes to the ootb program.cs etc. using defaults
k
What's the
aspnetcore_environment
in Azure?
d
"Development", But this is when running it localy in vs on on azure itself yet.
k
Where is the connection string declared when running locally in VS?
d
Just to clarify when we use the umbraco method for getting the conn info from our _config it is retrieving the correct value https://cdn.discordapp.com/attachments/1260506916623355926/1260875889323802655/0.png?ex=6690e9ad&is=668f982d&hm=4b6c819ba73a8792d113b4e104f10116e5436116a74a042731df0731354606d2&
the conn string is being read for an azure appConfiguration service in azure
k
When running locally from VS? How?
k
Hmm. Why are you doing it this way?
Is it because you want to "move our configuration out of app settings and into azure app configuration and key vault for secrets" even for local development?
d
yeah
k
Why not just use user secrets for local development, and key vault for Azure?
d
We have inconsistant config localy amoung the team and we're standadising it so that when running localy we will simple bring down configs labeled development. when running in test we bring down labeled test, sandbox for sandbox and prod for prod etc
k
Where exactly is the development configuration declared in Azure?
d
in the appconfiguration service. we're using labels to differentiate the different configs
so that's part of the configuration on appconfiguration
k
So, in actual Umbraco runtime the Azure App Configuration config source isn't being used, which leads to the "Umbraco not installed" problem. But you can see in code that the config source actually works, even when using Umbraco methods to retrieve configuration.
d
this works fine the variables are available they have the same key, and when running _config.GetUmbracoConnectionString(out var name); we get the correct value
k
If you define a connection string in
appSettings.Development.json
, does Umbraco recognize that?
d
yeah so if i put the conn string into appsettings it works fine
k
How does Umbraco retrieve the
DefaultAzureCredential
? When you run locally, it would use your user credentials?
d
when debuging the umbraco i can see that when it runs the AddUmbraco(_env, _config) extension it is getting the correct conn string but later when it's running the .AddBackOffice() it gets a completly different IConfiguration
yeah we use our azure creds
this is where we're setting up umbraco
the AzureAppConfigurationProvider in _config is from azure app configuration and has the conn string in as expected
k
Have you tried doing
.AddAzureAppConfiguration
before
.AddConfiguration
?
d
I have. i was wondering if perhaps it was taking a .first() of the providers at some point myself
no luck same result
k
This sounds like a bug in Umbraco. No idea why
.AddBackOffice
would somehow get configuration without one of the configuration providers. But it does sound like a timing issue.
d
Thanks for your help anyway I appreciate your time.
It's a real mystery though 😦
k
No problem. Thanks for the App Configuration idea, it looks like something that could be useful to us as well.
d
If i get it working i'll let you know
k
Yes, the only thing I can think about is the Umbraco bootstrap pipeline doing something that invalidates one of the chained configuration providers during
AddBackoffice
for some reason.
d
Potentialy fixed it. So Umbraco does apear to be using the service provider to get the IConfiguration somtimes instead of the one i passed into it when making the builders. so i've replaced the iconfiguration service in service provider with my IConfiguration services.Replace(ServiceDescriptor.Singleton(typeof(IConfiguration), _config)); And that seems to have worked.
k
oof. That's definitely a bug I'd say
Good catch!
39 Views