#Correct setup for the config file and different servers

1 messages · Page 1 of 1 (latest)

bleak night
#

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?

light leaf
#

use secrets appsettings for your local settings.

brazen flume
#

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

subtle mist
#

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

silent shell
#

@bleak night 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).

bleak night
rotund mirage
#

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.