- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 .Net Core 中寻找构建 appsettings.json 文件的明智方法。
是否应该将基本的“appsettings.json”文件配置为在开发环境中运行,然后基于环境的覆盖(例如 appsettings.production.json)覆盖生产的特定 key ?
或者 appsettings.json 应该只包含在所有环境中共享的配置,然后使用特定的 appsettings.development/staging.json 文件为这些环境显式设置 key ?
我担心的是 - 假设应用程序部署到实时服务器,但存储在环境变量(例如覆盖连接字符串)中的 key 丢失或拼写错误等。在这种情况下,应用程序将回退到基础 appsettings.json连接字符串,这对于实时环境来说是不正确的数据库。像这样的场景听起来非常灾难性,特别是因为这很容易被忽视?
所以真的问题归结为 - 基本 appsettings.json 文件的内容是否应该是默认的“开发”值(例如开发数据库、沙箱 API),并被生产数据覆盖,反之亦然?
最佳答案
我认为这个答案很无聊;这取决于。但我最喜欢的方法是这样的:
appsetting.json (base settings)
appsettings.development.json (dev with no secrets)
appsettings.production.json (production with no secrets)
{
"ConnectionStrings": {
“dbConnection: “data source=localhost” <—— only here
},
“environment”: “local”,
"Logging": {
"LogLevel": {
"Default": “Verbose”
}
},
}
{
“environment”: “development”,
"Logging": {
"LogLevel": {
"Default": “Warning”
}
},
}
{
“environment”: “production”,
"Logging": {
"LogLevel": {
"Default": “Information”
}
},
}
My concern is - say an app is deployed to a live server, but a key stored in an environment variable (e.g. to override connection string) is missing or spelt wrong etc. In this case the app would fall back to the base appsettings.json connection string which would be the incorrect DB for the live environment. A scenario like this sounds pretty disasterous, particularly as this could easily go unnoticed?
关于.Net Core appsettings.json 最佳实践 - 覆盖开发设置(反之亦然)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62087066/
我可以拥有吗?我的 app.config 中的部分包含许多设置,但也引用了 不同文件中的部分? 这将允许我保留只有开发人员应该感兴趣的配置选项,例如在主窗口上显示调试输出的选项(非常困惑但对我有用)或
我正在使用通过控制台应用程序创建的 app.config 文件,我可以使用 ConfigurationSettings.AppSettings["key1"].ToString()
我搜索了该站点,虽然我找到了一些非常有用的信息,但我无法弄清楚我的代码发生了什么。我有以下 web.config: 我
我正在使用 az functionapp config appsettings 自动创建我的 Azure Function 设置。我的设置之一是其中包含空格的 SQL 连接字符串。连接字符串中的空格导
我正在使用 az functionapp config appsettings 自动创建我的 Azure Function 设置。我的设置之一是其中包含空格的 SQL 连接字符串。连接字符串中的空格导
工具:VS2017、ASP.NET Core 2、Entity Framework Core 2、ASP.NET Core JavaScript 服务 我正在使用以下 BuildWebHost 方法:
我正在使用 ASP.NET Core 2.1。我在 appsettings.json 中有设置我使用选项模式将它们绑定(bind)到类。我想在 appsettings.Production.json
我在 appsettings.Development.json 上有点挣扎覆盖或以其他方式与 appsettings.json 合并.我不确定如何使用 appsettings.Development.
我真的很希望能够有一种方法来获取当前使用 ConfigurationManager.AppSettings [“mysettingkey”] 来获取其设置的应用程序,以使这些设置实际上来自中央数据库而
我有一些需要从多个文件访问的字符串常量。由于这些常量的值可能会不时更改,因此我决定将它们放在 AppSettings 而不是常量类中,这样我就不必在每次更改常量时都重新编译。 有时我需要处理单个字符串
我的 App.config 中有这样的代码片段 - 在 master_AppSettings.config 文件中,我将“ApplicationDSN”设置为“ABCConnectionStri
我有一个希望非常简单的问题。 如果我有值,我想从 Web.config 的 AppSettings 中找到某个键 为了简单起见,是否可以通过指定值而不是键来找到 AppSettings 条目
我正在使用 .NET Web API(4.6 框架)编写应用 我有一个我使用的属性:[ApiExplorerSettings(IgnoreApi = true)] 从我的 Swagger 中隐藏某些
在我的办公室,我们认为我们要将 Web.Config 的 AppSettings 放入数据库中。因此,我创建了以下内容,但对代码的几个方面有一些疑问。 所以我的问题是: UTILITY 类中包含“Ca
有人能帮我理解为什么在向配置文件添加值后,我不能立即将其读入应用程序吗?我做了刷新,但这不起作用。见下文: public void AddConfig(string key_value, st
我想从名为 MyAssembly.dll.config 的程序集配置文件中检索 AppSetting key 。这是配置文件的示例: 这是检索它的代码: va
我正在为 .NET 2.0 中的配置和设置类而苦苦挣扎 如果以下内容包含在名为 app.config 的文件中 我知道我可以通过以下方式访问 appSetting // this retur
我想从名为 secrets.config 的外部配置文件中读取控制台应用程序的 appSettings 的一部分,而其余部分我想从 app.config 中读取。 目前,我已经设置好了,但它似乎没有从
我有一个配置文件 app.exe.config 和 appSettings 部分有这样的东西: app.file.config 文件有这样的东西: 我需要在运行时
我目前正在从事 asp.net core (c#) Web API 项目。 对 Web API 的每次调用都将有一个唯一的 key ,以帮助识别进行调用的用户。 每个调用者都会有一组特定的配置值与之关
我是一名优秀的程序员,十分优秀!