用户机密路径:C:\Users{UserName}\AppData\Roaming\Microsoft\UserSecrets{ID}
在项目文件中可以看到该用户机密的 ID:
右键文件标签,可以直接打开所在目录:
回顾 ASP.NET Core 程序配置信息来源:
- appsettings.json
- appsettings{环境变量}.json
- 用户机密
- 环境变量
命令行参数
builder.UseKestrel((builderContext, options) =>
{
options.Configure(builderContext.Configuration.GetSection("Kestrel"));
})
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
if (env.IsDevelopment())
{
var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
if (appAssembly != null)
{
config.AddUserSecrets(appAssembly, optional: true);
}
}
config.AddEnvironmentVariables();
if (args != null)
{
config.AddCommandLine(args);
}
})
...