教程:在 Azure 应用程序配置中管理功能标志Tutorial: Manage feature flags in Azure App Configuration

可将所有功能标志存储在 Azure 应用程序配置中,并从一个位置对其进行管理。You can store all feature flags in Azure App Configuration and administer them from a single place. 应用程序配置提供一个名为“功能管理器”的门户 UI 专为功能标志而设计。 App Configuration has a portal UI named Feature Manager that's designed specifically for feature flags. 应用程序配置还原生支持 .NET Core 功能标志数据架构。App Configuration also natively supports the .NET Core feature-flag data schema.

在本教程中,你将了解如何执行以下操作:In this tutorial, you learn how to:

  • 在应用程序配置中定义和管理功能标志。Define and manage feature flags in App Configuration.
  • 从应用程序访问功能标志。Access feature flags from your application.

创建功能标志Create feature flags

应用程序配置的 Azure 门户中的“功能管理器”提供一个 UI 用于创建和管理应用程序中使用的功能标志。The Feature Manager in the Azure portal for App Configuration provides a UI for creating and managing the feature flags that you use in your applications.

若要添加新功能标志,请执行以下操作:To add a new feature flag:

  1. 选择“功能管理器” > “+添加”以添加功能标志。 Select Feature Manager > +Add to add a feature flag.

    功能标志列表

  2. 输入功能标志的唯一键名称。Enter a unique key name for the feature flag. 需要使用名称在代码中引用标志。You need this name to reference the flag in your code.

  3. 如果需要,请为功能标志提供说明。If you want, give the feature flag a description.

  4. 设置功能标志的初始状态。Set the initial state of the feature flag. 此状态通常是“关” 或“开” 。This state is usually Off or On. 如果向功能标志添加筛选器,则“开” 状态将更改为“条件” 。The On state changes to Conditional if you add a filter to the feature flag.

    创建功能标志

  5. 当状态为“开”时,选择“+添加筛选器”以指定任何其他条件来限定状态 。When the state is On, select +Add filter to specify any additional conditions to qualify the state. 输入内置或自定义筛选键,然后选择“+添加参数” 以将一个或多个参数与筛选器关联。Enter a built-in or custom filter key, and then select +Add parameter to associate one or more parameters with the filter. 内置筛选器包括:Built-in filters include:

    密钥Key JSON 参数JSON parameters
    Microsoft.PercentageMicrosoft.Percentage {"Value":0-100 percent}{"Value": 0-100 percent}
    Microsoft.TimeWindowMicrosoft.TimeWindow {"Start":UTC time, "End":UTC time}{"Start": UTC time, "End": UTC time}
    Microsoft.TargetingMicrosoft.Targeting {“受众”:定义用户、组和推出百分比的 JSON blob。{ "Audience": JSON blob defining users, groups, and rollout percentages. 请参阅此设置文件EnabledFor 元素下的示例}See an example under the EnabledFor element of this settings file }

    功能标志筛选器

更新功能标志状态Update feature flag states

若要更改功能标志的状态值,请执行以下操作:To change a feature flag's state value:

  1. 选择“功能管理器”。Select Feature Manager.

  2. 在要修改的功能标志的右侧,选择省略号 (...),然后选择“编辑”。To the right of a feature flag you want to modify, select the ellipsis (...), and then select Edit.

  3. 设置功能标志的新状态。Set a new state for the feature flag.

访问功能标志Access feature flags

“功能管理器”创建的功能标志作为常规的键值进行存储和检索。Feature flags created by the Feature Manager are stored and retrieved as regular key values. 它们保存在特殊的命名空间前缀 .appconfig.featureflag 下。They're kept under a special namespace prefix .appconfig.featureflag. 若要查看基础键值,请使用配置资源管理器。To view the underlying key values, use the Configuration Explorer. 应用程序可以使用应用程序配置的配置提供程序、SDK、命令行扩展和 REST API 来检索这些值。Your application can retrieve these values by using the App Configuration configuration providers, SDKs, command-line extensions, and REST APIs.

后续步骤Next steps

本教程已介绍如何使用应用程序配置管理功能标志及其状态。In this tutorial, you learned how to manage feature flags and their states by using App Configuration. 有关应用程序配置和 ASP.NET Core 中的功能管理支持的详细信息,请参阅以下文章:For more information about feature-management support in App Configuration and ASP.NET Core, see the following article: