Correct setup for the config file and different se...
# help-with-umbraco
t
Hi I have 2 servers, test and production. I setup my Umbraco with app settings as below appsettings.json - local development appsettingsDevelopment.json - test server appsettingsProduction.json - production server Local uses SQLLite. If I have different connection string settings in appsettings (for my local development) and development files my local version never works and throws an error. If I remove the connection string from development then everything works locally but it means I've got a development config file that is now wrong. Am I missing something?
m
use secrets appsettings for your local settings.
a
In .NET applications, the ASP.NET Core configuration system loads configuration in a specific order, which includes merging and overriding settings based on the environment.
appsettings.json: This is the base configuration file. It is always loaded.
appsettings.{Environment}.json: This file overrides the settings in appsettings.json based on the ASPNETCORE_ENVIRONMENT variable.
The key is that each file is merged into a single configuration object. So, if you define the same setting in multiple files, the one with higher precedence (based on environment) will be used.
Also it's a good approach to never store connectionstring settings in your appsetting file, also making sure you never commit those, except for your (local) dev environment perhaps
for others you could use a keyvault or secrets appsettings as Mike said
m
Umbraco adds a appsettings.local.json to the config. I tend to use appSetting.json as production The environment versions to override good defaults. Modelsbuilder for example is only in my local version
Local doesn't get commit to git same as secrets they are in KV
s
@TigerMan Ambert has given you the answer but I just want to check you've seen the subtle difference. You said you have: appsettingsDevelopment.json - test server appsettingsProduction.json - production server These should be appsettings.Development.json - test server appsettings.Production.json - production server The environment variable is between the two dots - this might explain your confusion and why things aren't working as you'd expect (or you had a simple typo in your question).
t
Hi yes I noticed that.... My phone auto corrected it and I didn't change it back. Thanks for highlighting 👍
k
The typical scenario is - appSettings.json - global settings that apply to all environments (e.g., general Umbraco config) - appSettings.Development.json - settings that apply to all development environments (e.g., runtime mode development) - appSettings.[Environment].json - environment settings (e.g., runtime mode, connection strings) - user secrets - development-environment-specific config (e.g., connection strings, email addresses) Not sure if user secrets can get the Umbraco and other schemas, otherwise just copy a full appSettings and modify it. So, don't use appSettings.json for any "local development" config.
m
as the user secrets.appsettings exist at
C:\Users\mikec\AppData\Roaming\Microsoft\UserSecrets\{GUID}
as long as you update the schema to be an absolute path to the
./appsettings-schema.json
you can get the intellisence in the secrets. eg
"$schema": "D:\\_work\\PROJECT\\src\\www\\appsettings-schema.json",
25 Views