【问题标题】:Read Azure Portal Application Settings of the Static Web App service using Blazor WASM使用 Blazor WASM 读取静态 Web 应用服务的 Azure 门户应用程序设置
【发布时间】:2022-01-24 09:36:52
【问题描述】:

我正在 Azure 静态 Web 应用上运行 Blazor WASM 应用程序。 在我的 .NET6 C# 应用程序中,我想阅读我在门户中添加的设置。 我没有使用也不想使用 appsettings.json 或 web.config。我想读取我在门户中添加的值。

我已经读了好几天了。我发现了很多关于服务器端解决方案的页面,我无法使用,因为我只运行客户端。

我假设我需要在我的 program.cs 中做一些事情:

static void ConfigureServices(IServiceCollection services, string baseAddress)
{
    services.AddTransient(_ => new HttpClient(new DefaultBrowserOptionsMessageHandler(new HttpClientHandler())
    {
        DefaultBrowserRequestCache = BrowserRequestCache.ForceCache,
        DefaultBrowserRequestMode = BrowserRequestMode.Cors
    })
    {
        BaseAddress = new Uri(baseAddress)
    });

    // TODO make the settings from the portal available for all pages and components
}

我不确定如何注入设置。

我想我需要像这样在我的页面上使用它:

@page "/"
@inject IConfiguration _configuration

<h1>Hello, world!</h1>

<p>Welcome to your new app.</p>
<p>Config: @_configuration["Foo"]</p>
<p>Env: @Environment.GetEnvironmentVariable("Foo")</p>

<SurveyPrompt Title="How is Blazor working for you?" />

请指教。

【问题讨论】:

  • 您找到解决方案了吗?
  • 我没有找到解决方案。我正在使用一种解决方法,即根据我是处于开发模式(本地)还是生产模式(已发布)对我需要的变量进行硬编码。

标签: azure configuration blazor-webassembly azure-static-web-app


【解决方案1】:

目前,应用程序设置仅适用于与 Blazor 应用关联的后端 API(使用 azure 静态 Web 应用时)。

详情请咨询Configure application settings for Azure Static Web Apps

【讨论】:

    猜你喜欢
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-02
    • 2021-05-12
    • 1970-01-01
    • 2021-04-05
    • 2020-05-17
    相关资源
    最近更新 更多