如何通过Azure应用设置中的Web.Config管理自定义部分?

时间:2019-07-19 20:11:07

标签: c# azure settings

我的web.config中有此自定义部分

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

我将Web应用托管在Azure上,并且希望能够在Azure应用设置中添加新的userAccount。

我尝试过:

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

OR

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

但是它不起作用。我可以在本地主机上阅读web.config自定义部分,但在托管应用程序时看不到。

你能帮我吗?

2 个答案:

答案 0 :(得分:0)

您只能使用Azure的管理API编写应用程序设置。有关使用Fluent SDK的示例,请参见此处。否则,设置在应用程序内为只读。 https://stackoverflow.com/a/50116234

答案 1 :(得分:0)

如果您不想在“配置”中配置应用程序设置,则可以按照本教程进行:Configure app settings Web.config 中的标签<appSettings>下进行配置,但是App Service中的值将覆盖Web.config中的值。

以下是我的测试:

enter image description here

并使用System.Configuration.ConfigurationManager.AppSettings["testkey"]来获取值,下面的页面是在Azure中使用主机获取值。

enter image description here

希望这可以为您提供帮助。