azure - 使用 Blazor WASM 读取静态 Web 应用服务的 Azure 门户应用程序设置

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

我正在 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
}

我不确定如何注入(inject)设置。

我想我需要在我的页面上使用它,如下所示:

@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?" />

请指教。

最佳答案

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

请引用Configure application settings for Azure Static Web Apps获取详细信息。

关于azure - 使用 Blazor WASM 读取静态 Web 应用服务的 Azure 门户应用程序设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70461295/

相关文章:

powershell - 在 Azure PowerShell 中向 ARM 和 ASM 进行一次身份验证

Java 国际奥委会 : distributed configuration

javascript - nodejs中的 `rc`文件是什么?

.net - 使用 clickonce 部署时不要覆盖 app.config

azure - Azure 中托管的 Blazor Web assembly Azure AD 身份验证在签名后返回 404

azure - 从 Azure 功能调用 Azure Active Directory 密码重置策略

azure - 在 Windows Azure 中将 DS 与 D1_V2 VM 混合

java - 在 KeyVaultClient java 中将代理设置为 AuthenticationContext 没有效果

c# - NET5.0 Blazor WASM CORS 客户端异常

asp.net - Blazor Webassembly 身份验证非常慢