【发布时间】:2021-05-31 02:06:43
【问题描述】:
- 我正在开发 Blazor WebAssembly 客户端/服务器项目(目录结构如上)
- 在客户端和服务器项目中都有一些应用程序设置。
- 项目托管在 Azure 中。
问题出在客户端,appsettings.json
- 在客户端,
appsettings.json位于wwwroot目录中。可以在应用内访问文件,但是应用服务的 Azure Portal Application Settings 无法覆盖这些设置。
这意味着,在 Web 应用服务上的 Azure 门户中部署应用程序后,我的配置设置不适用于应用程序设置的变量。
这是Progam.cs中的代码,可以正常工作并从文件中读取配置,但忽略Azure上Web App Service的配置设置。
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
//Add a named httpClient and set base Address and Default Request Headers
builder.Services.AddHttpClient("SOME_WEB_URL", client => // SOME_WEB_URL is defined in the appsettings.json or in the Azure App Service configuration (Application Settings)
{
client.BaseAddress = new Uri(builder.Configuration["sbformsapi"]);
});
//Add a named httpClient and set base Address and Default Request Headers
builder.Services.AddHttpClient("WEB_APP_API", client => // WEB_APP_API is defined in the
{
client.BaseAddress = new Uri(builder.Configuration["sbwebappapi"]);
});
builder.Services.AddAuthorizationCore();
....
await builder.Build().RunAsync();
}
有人可以指导我怎么做
- 将appsettings.json 文件设置在wwwroot 之外并从那里读取? 或
- 在运行时注入/使用 Azure 应用服务配置的应用程序设置中的值?
这里说的是应用设置(如图)...
【问题讨论】:
-
如果其中有任何秘密,您可以实现一个返回特定于前端的配置项的 API。看看这里:ASP.NET Core Blazor configuration.
-
@wafers 你找到解决办法了吗?
标签: azure azure-web-app-service blazor blazor-webassembly blazor-client-side