RHG*_*RHG 5 .net c# configuration json asp.net-core
我在尝试读取用户机密时遇到问题。我在startup.cs中的代码如下:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json",
optional: false,
reloadOnChange: true);
if (env.IsDevelopment())
{
builder.AddUserSecrets<Startup>(false);
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)
从 appsettings.json 和环境变量读取工作正常,但无论我在 Secrets.json 文件中放入什么内容,都不会从中读取任何值。项目文件中UserSecretsId的值是正确的,并且env.IsDevelopment()是true。
配置包含三个提供程序。一个 JsonConfigurationProvider 包含来自 appsettings.json 的数据,一个 EnvironmentVariablesConfigurationProvider 包含来自环境变量的值,还有一个 JsonConfigurationProvider 没有数据。我认为后一种是添加用户机密的一种。但为什么是空的呢?