读取Blazor WebAssembly App的设置会返回旧值

问题描述

我有两个设置文件。 appsettings.json和web.settings.json。都需要阅读两者才能获得一些设置。

        // read JSON file as a stream for configuration
        var client = new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) };

        builder.Services.AddScoped(sp => client);

        // the appsettings file must be in 'wwwroot'
        using var response = await client.GetAsync("appsettings.json");
        using var stream = await response.Content.ReadAsstreamAsync();
        builder.Configuration.AddJsonStream(stream);

        using var webSettingsResponse = await client.GetAsync("web.settings.json");
        using var webSettingsstream = await webSettingsResponse.Content.ReadAsstreamAsync();
        builder.Configuration.AddJsonStream(webSettingsstream);

在那之后,我阅读了这样的设置

var apiUrl = builder.Configuration["ApiUri"];

我首先运行应用程序,它读取正确的密钥,并设置了localhost:8002。 但是,当我将web.settings.json中的值更改为localhost:8001(只是端口更改)时,每次运行该应用程序时,它仍为我提供旧的8002。

web.settings.json:

  • 构建操作内容并始终复制。
  • 文件位于wwwroot中
  • 如果我正在运行并检查bin \ Debug \ netstandard2.1 \ wwwroot中的web.settings.json,则将端口8001作为设置在那里

为什么我仍然可以得到8002?它缓存在某个地方吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)