You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Blazor WebAssembly部署Azure App Service后无法读取应用设置及重命名报错

Blazor WebAssembly部署Azure App Service:配置读取失败与应用设置重命名报错问题

将Blazor WebAssembly应用部署到Azure App Service部署槽后,遇到两个问题:

  1. 无法读取在部署槽应用设置中定义的密钥变量
  2. 尝试重命名应用设置变量时触发报错

相关配置信息

部署槽应用设置说明

部署槽中已定义AzureAdB2CAuthority、AzureAdB2CClientId、AzureAdB2CValidateAuthority三个配置项

Program.cs核心配置代码

services.AddMsalAuthentication<RemoteAuthenticationState, CustomUserAccount>(options =>
{
    options.ProviderOptions.Authentication.Authority = builder.Configuration.GetValue<string>("AzureAdB2CAuthority");
    options.ProviderOptions.Authentication.ClientId = builder.Configuration.GetValue<string>("AzureAdB2CClientId");
    options.ProviderOptions.Authentication.ValidateAuthority = builder.Configuration.GetValue<bool>("AzureAdB2CValidateAuthority");
    //builder.Configuration.Bind("AzureAdB2C", options.ProviderOptions.Authentication);
    options.ProviderOptions.DefaultAccessTokenScopes.Add("openid");
    options.ProviderOptions.DefaultAccessTokenScopes.Add("offline_access");
    options.ProviderOptions.DefaultAccessTokenScopes.Add("XXXX");
    options.ProviderOptions.LoginMode = "redirect";
})
        .AddAccountClaimsPrincipalFactory<RemoteAuthenticationState,CustomUserAccount, CustomAccountFactory>();

appsettings.json内容

{
  "AzureAdB2CAuthority": "XXXXXXXXXX",
  "AzureAdB2CClientId": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
  "AzureAdB2CValidateAuthority": false
}

重命名报错说明

重命名应用设置时触发无效应用设置名称提示,提示内容为“名称不能包含点号(.)、冒号(:)或空格”,疑问是否与服务计划有关


问题解决方法

1. 无法读取应用设置变量的解决方案

Blazor WebAssembly是客户端运行的应用,默认无法直接获取Azure App Service服务器端的应用设置,需通过以下方式处理:

  • 客户端暴露配置:将需要客户端读取的应用设置名称添加前缀BlazorConfiguration__,例如将AzureAdB2CAuthority改为BlazorConfiguration__AzureAdB2CAuthority。客户端代码无需修改,builder.Configuration.GetValue仍可通过原键名读取(Azure会自动将前缀映射到客户端配置节点)。
  • 服务器端中转(敏感场景):若涉及敏感密钥,可在服务器端新增API接口,将配置返回给客户端(需做好权限验证,避免敏感信息泄露)。
  • 确认部署配置:确保部署时启用了“应用设置覆盖appsettings.json”,保证部署槽设置优先级高于本地配置。

2. 应用设置重命名报错的解决方案

该错误与服务计划无关,是违反Azure App Service应用设置命名规则导致:应用设置名称不能包含点号(.)、冒号(:)或空格。
解决方法:重命名时使用合规名称,例如用下划线_代替点号,或调整名称避免禁用字符。


内容的提问来源于stack exchange,提问作者b-612

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 15:56:27