应用程序不加载 azure app config 功能标志值但加载配置值
Application doesn't load azure app config feature flag value but loads config values
我有一个 Blazor 应用程序,我想使用 Azure 应用程序配置。
我已成功设置获取配置值,但它没有找到我的功能标志。
当我注入 IConfiguration 并查询配置值的值时,就像这样 Configuration["value"]
检索到正确的数据。
但是当我尝试检查我唯一的功能标志是否已启用(并且它是)时,结果总是错误的,我想这是因为应用程序找不到功能标志,而不是因为它正在读取值错误(传递不存在的功能标志的名称会导致该方法 return“false”)。
Startup.cs:
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;
using Microsoft.FeatureManagement;
namespace OreNoAppu
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));
services.AddControllersWithViews().AddMicrosoftIdentityUI();
// By default, all incoming requests will be authorized according to the default policy
services.AddAuthorization(options => options.FallbackPolicy = options.DefaultPolicy);
services.AddRazorPages();
services.AddServerSideBlazor().AddMicrosoftIdentityConsentHandler();
services.AddFeatureManagement();
services.AddAzureAppConfiguration();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days.You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAzureAppConfiguration();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
}
Program.cs:
using Azure.Core;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using BoomiLogReader.Utility;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System;
namespace OreNoAppu
{
public class Program
{
public static void Main(string[] args)
{
InitKeyVault();
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
webBuilder.ConfigureAppConfiguration(config =>
{
var connection = KeyVaultReader.GetSecretValue("AzureAppConfigConnStr");
config.AddAzureAppConfiguration(options =>
options.Connect(connection).UseFeatureFlags());
}).UseStartup<Startup>());
// Initialises KeyVaultReader, which is used to retrieve secrets from Azure Key Vault.
public static void InitKeyVault()
{
// N'importe quoi, access to KeyVault and getting of the conn string works fine.
}
}
}
应该获取标志的代码:
@using Microsoft.FeatureManagement
@inject IFeatureManager featureManager
@if (featureEnabled)
{
<h1>Yes</h1>
}
@code
{
bool featureEnabled = true;
protected override async Task OnInitializedAsync()
{
featureEnabled = featureManager.IsEnabledAsync("OreNoFlaggu").Result;
}
}
调试,我看到方法调用“IsEnabledAsync”returns“false”,但我的应用程序配置中有一个“OreNoFlaggu”功能标志,应用程序成功连接并从中检索配置值,并启用所述标志。
知道为什么它不起作用吗?
@Tessaract,您的功能标志是否恰好在您的 App Config 商店中有一个标签。如果是这样,请不要忘记在通过 FeatureFlagOptions.Label
.
调用 UseFeatureFlags()
时传递标签
我有一个 Blazor 应用程序,我想使用 Azure 应用程序配置。
我已成功设置获取配置值,但它没有找到我的功能标志。
当我注入 IConfiguration 并查询配置值的值时,就像这样 Configuration["value"]
检索到正确的数据。
但是当我尝试检查我唯一的功能标志是否已启用(并且它是)时,结果总是错误的,我想这是因为应用程序找不到功能标志,而不是因为它正在读取值错误(传递不存在的功能标志的名称会导致该方法 return“false”)。
Startup.cs:
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;
using Microsoft.FeatureManagement;
namespace OreNoAppu
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));
services.AddControllersWithViews().AddMicrosoftIdentityUI();
// By default, all incoming requests will be authorized according to the default policy
services.AddAuthorization(options => options.FallbackPolicy = options.DefaultPolicy);
services.AddRazorPages();
services.AddServerSideBlazor().AddMicrosoftIdentityConsentHandler();
services.AddFeatureManagement();
services.AddAzureAppConfiguration();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days.You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAzureAppConfiguration();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
}
Program.cs:
using Azure.Core;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using BoomiLogReader.Utility;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System;
namespace OreNoAppu
{
public class Program
{
public static void Main(string[] args)
{
InitKeyVault();
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
webBuilder.ConfigureAppConfiguration(config =>
{
var connection = KeyVaultReader.GetSecretValue("AzureAppConfigConnStr");
config.AddAzureAppConfiguration(options =>
options.Connect(connection).UseFeatureFlags());
}).UseStartup<Startup>());
// Initialises KeyVaultReader, which is used to retrieve secrets from Azure Key Vault.
public static void InitKeyVault()
{
// N'importe quoi, access to KeyVault and getting of the conn string works fine.
}
}
}
应该获取标志的代码:
@using Microsoft.FeatureManagement
@inject IFeatureManager featureManager
@if (featureEnabled)
{
<h1>Yes</h1>
}
@code
{
bool featureEnabled = true;
protected override async Task OnInitializedAsync()
{
featureEnabled = featureManager.IsEnabledAsync("OreNoFlaggu").Result;
}
}
调试,我看到方法调用“IsEnabledAsync”returns“false”,但我的应用程序配置中有一个“OreNoFlaggu”功能标志,应用程序成功连接并从中检索配置值,并启用所述标志。
知道为什么它不起作用吗?
@Tessaract,您的功能标志是否恰好在您的 App Config 商店中有一个标签。如果是这样,请不要忘记在通过 FeatureFlagOptions.Label
.
UseFeatureFlags()
时传递标签