2

I have this custom section in my web.config

  <defaultUserAccounts>
    <userAccount email="x@x.com" password="xxx" />
    <userAccount email="y@y.com" password="yyy" />
  </defaultUserAccounts>

I host my web app on Azure and I want to be able to add new userAccount in the Azure App Settings.

I tried with:

defaultUserAccounts.userAccount.email / z@z.com
defaultUserAccounts.userAccount.password / zzz

OR

defaultUserAccounts:userAccount:email / z@z.com
defaultUserAccounts:userAccount:password / zzz

But it doesnt work. I can read the web.config custom section in localhost, but not when the app is hosted.

Could you help me?

Cedric Arnould
  • 1,991
  • 4
  • 29
  • 49
  • A couple thoughts, but not towards an answer. Are you planning on ever moving to Core? Have you considered doing this a much better way? Like a database? As this approach isn't really the right way... https://learn.microsoft.com/en-us/azure/azure-app-configuration/overview – Austin T French Jul 19 '19 at 21:40
  • We dont want to move to core. We doesnt want to use a database. This way is the way we want. We need to have the list of user available in the web.config. Do you have a solution to help me? – Cedric Arnould Jul 20 '19 at 02:19

2 Answers2

0

You can only write the app settings using the management API of Azure. See here for an example using the Fluent SDK. Otherwise the settings are read-only from within the app. https://stackoverflow.com/a/50116234

silent
  • 14,494
  • 4
  • 46
  • 86
  • Thanks, yeah, in a way it could work, but I would like to imagine there is another solution built in in azure already. – Cedric Arnould Jul 23 '19 at 04:08
  • Feel free to look for another way but as I said, the settings are read only for the app. – silent Jul 23 '19 at 04:12
  • Maybe I dont understand something, but in Azure / Configuration / Application Settings I can edit the settings, so it s not read only. Did I miss something? – Cedric Arnould Jul 23 '19 at 14:27
  • Yes, you misunderstood something ;) When you are working in the Azure Portal you are interacting with the Management plane of the App Service. This uses your user credentials which has the required permissions. Within the app itself, you are in the Compute plane. This is completely separated from the management - for good reasons. To make calls against the management plane, you need to use something like the Fluent SDK (or other SDKs available) - and use an identity with the required permissions. – silent Jul 23 '19 at 15:28
  • Ok, now I understand, thanks for the explanation. If I understand well, it s not possible to overwrite the custom configuration section of the web.config in the Azure App Settings, only the section AppSettings of the Web.config can be overwritten. Your suggestion is to use the Fluent SDK, so the azure webapp will connect to Azure and will be able to get the settings from the Azure settings. Do I understand correctly? – Cedric Arnould Jul 24 '19 at 20:17
-1

If you don't want to configure app setting in the Configuration you could follow this tutorial:Configure app settings configure it under tag <appSettings> in Web.config, but the values in App Service override the ones in Web.config.

The below is my test:

enter image description here

And use System.Configuration.ConfigurationManager.AppSettings["testkey"] to get the value, the below page is get the value with host in Azure.

enter image description here

Hope this could help you.

George Chen
  • 13,703
  • 2
  • 11
  • 26
  • Hi, thank for your try but sory it was not my question :). In my case, I have a custom configuration. In your case you use the standard settings. Or did I miss something in your answer? – Cedric Arnould Jul 23 '19 at 04:06