0

在 Azure 应用程序配置中,您可以存储具有多个值的键,按标签区分。

在构建配置时,可以使用labelFilter="SomeLabel"过滤从存储中读取的键

在我的情况下,我在应用商店中有 50 个没有任何标签(No Label)的键,以及 4 个具有两个值的键,一个值用于标签SomeLabel,另一个值用于(No Label)

我想检索所有 54 个键。对于具有多个值的 4 个键,我想要带有标签SomeLabel的值。

如果我使用labelFilter="SomeLabel"我只得到带有标签的 4 个键,则过滤掉没有任何标签的 50 个键。

是否有可能实现我想要的功能?

 <configBuilders>
    <builders>
      <add name="SomeAzureAppConfigStore" labelFilter="SomeLabel" mode="Greedy" prefix="My.App:" stripPrefix="true" connectionString="${MyConnectionString}" useAzureKeyVault="true" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxx" />
    </builders>
  </configBuilders>
4

2 回答 2

1

You can resolve this by defining multiple configbuilders. The first builder will get all keys (although documentation suggests it should only be keys without labels). The second builder will override any previous key/values with the environment specific key/value. Note that the order in the tag also matters for the order in which the override occurs.

<configBuilders>
    <builders>
        <add name="SomeAzureAppConfigStoreNoLabel"
            labelFilter=""
            mode="Greedy" prefix="My.App:" stripPrefix="true" connectionString="${MyConnectionString}" useAzureKeyVault="true" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxx" />
        
    <add name="SomeAzureAppConfigStoreSomeLabel"
        labelFilter="SomeLabel"
        mode="Greedy" prefix="My.App:" stripPrefix="true" connectionString="${MyConnectionString}" useAzureKeyVault="true" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxx" />
    </builders>
</configBuilders>

<appSettings configBuilders="SomeAzureAppConfigStoreNoLabel,SomeAzureAppConfigStoreSomeLabel">
于 2020-09-03T18:31:44.433 回答
0

您的问题的解决方案是使用多个标签。如果您将“%00”设置为标签之一,则将其视为空标签。然后它将加载两组标签,根据它们设置的顺序,将导致使用您的其他 4 个标签而不是未标记的版本。

于 2020-03-18T16:54:20.317 回答