2

I have some .NET Framework 4.6.2 Web applications that I am trying to implement with Azure Keyvault for my organization. The applications live on-prem. Our app has web.config files for multiple environments (DEV, QA, TEST, PROD, etc.). There are some connectionStrings and appSettings, whose values we need to store in the KeyVault. All the environments have the same config keys in their web.config but the values are just environment specific.

Throughout the application our config keys are read like so: ConfigurationManager.AppSettings["ApiKey"] and ConfigurationManager.ConnectionStrings['DbContext'].ConnectionString.

I already have the keyvault setup and the secrets created just having trouble setting them in the ConfigurationManager. We want to be able to, on application startup, override the values for these keys with the secrets from the keyvault. The catch is that the values for the secrets should not be written to the web.config files. Is that possible or do we need some other Configuration implementation? We don't want to have to continuously interrogate Azure for the config setting. That is why we decided to do it once on startup and save to memory somehow. Once we hit Azure on startup we won't do it again until the next time the application is started.

Unfortunately, I cannot update these web applications to .NET Framework 4.7.1 at this time.

The existing microsoft documentation isn't really helpful for those of us still on older .NET Framework versions.

My apps are using Global.asax instead of the Startup.cs or Program.cs if that matters.

Bmoe
  • 888
  • 1
  • 15
  • 37
  • You can use the keyvault client to get secrets. Not all configuration has to be retrieved via ConfigurationManager. – Crowcoder May 27 '21 at 13:51
  • @Crowcoder Sorry if it wasn't clear, but updated the question to indicate we only want to call Azure once and then save the secret values in memory. Can you suggest what type of implementation to use? I can imagine if I am not using ConfigurationManager then I would have to refactor all of the ConfigurationManager calls or at least at a minimum the ConfigurationManager calls that are using same keys as in the keyvault. – Bmoe May 27 '21 at 14:20
  • You will need to do some refactoring. This is one reason I avoid doing configuration that way. I typically make an interface and the implementation gets values from wherever it needs to. The consumer of the implementation doesn't need to be concerned about config files or api calls or wherever settings come from – Crowcoder May 27 '21 at 14:31

0 Answers0