【问题标题】:Get server URL in Program.Main of a Blazor WebAssembly app在 Blazor WebAssembly 应用程序的 Program.Main 中获取服务器 URL
【发布时间】:2020-07-04 21:00:29
【问题描述】:

我希望我的 Blazor WebAssembly 应用程序中的 Program.Main 在启动应用程序之前调用为应用程序提供服务的服务器 - 这样我就可以从服务器获取一些配置设置。

有没有办法确定服务器 URL 是什么?

【问题讨论】:

    标签: blazor webassembly


    【解决方案1】:

    看起来我可以像这样在Program.Main 中发出服务器请求

    private static Task<ClientConfiguration> GetClientConfigurationAsync()
    {
        var serviceProvider = new ServiceCollection()
            .AddBaseAddressHttpClient()
            .BuildServiceProvider();
    
        var httpClient = serviceProvider.GetRequiredService<HttpClient>();
        return httpClient.GetJsonAsync<ClientConfiguration>("api/client-configuration");
    }
    

    【讨论】:

      猜你喜欢
      • 2020-07-04
      • 2023-04-03
      • 2020-12-18
      • 2019-12-22
      • 1970-01-01
      • 2021-02-24
      • 2020-02-12
      • 1970-01-01
      • 2022-09-29
      相关资源
      最近更新 更多