c# - ASP.NET Core appsettings.json 未加载正确的设置
问题描述
在我的 Azure 中,我有ENVIRONMENT = Development
,但我的设置没有加载。
public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) // reloadOnChange Whether the configuration should be reloaded if the file changes.
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ENVIRONMENT")}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables() // Environment Variables override all other, ** THIS SHOULD ALWAYS BE LAST
.Build();
但它始终使用默认设置。
解决方案
请更新您的以下行:
.SetBasePath(env.ContentRootPath)
推荐阅读
- c# - 创建 3D 阵列意见系统
- list - Haskell:如何创建一个空列表作为数据类型的选项?
- javascript - 在 SVG 路径中移动到鼠标单击 (d3.js)
- deep-learning - 推理时间短的分类模型
- php - 如何进行批量操作以将文件复制到谷歌驱动器,php?
- python-3.x - 在使用 Pandas Dataframe 生成的 CSV 中添加自定义页眉和页脚
- server - 将主 OPC UA 服务器连接到辅助 OPC UA 服务器
- amazon-web-services - 如何将 AWS Shield Advance 保护添加到我的堆栈?
- reactjs - 变量不迭代
- javascript - 为什么这个数组是空的?