Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve Wilkinson 132 posts 211 karma points
    Feb 03, 2022 @ 13:25
    Steve Wilkinson
    0

    appsettings.json and ConnectionString to umbraco database

    Umbraco v9 has four appsettings.json files in the root directory:

    • appsettings.Development.json
    • appsettings.json
    • appsettings.Production.json
    • appsettings.Staging.json

    When connecting to the Development database, does the ConnectionStrings go in appsettings.json or appsettings.Development.json please?

    If you put the connection to the Production server in appsettings.Production.json does that automatically end up in the appsettings.json file in bin\Release\ after running dotnet publish --configuration Release" please?

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Feb 03, 2022 @ 13:53
    Kevin Jump
    101

    Hi Steve,

    the appsettings.*.json files are actually merged together at runtime. So for example when you are running development, the settings in appsettings.development.json are merged over the settings in appsettings.json (so the settings from development will overwrite)

    when you run 'production' or 'staging' then those values are taken from the other files.

    which environment you are in is determined by the value of the ASPNETCORE_ENVIRONMENT variable (see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-6.0 ).

    By default in development this value is set from your properties/launchsettings.json file, so for example when you are running locally from dotnet run (or in visual studio) it will be set to `development'.

    When you publish all these different environmental files are actually copied into the publish directory, which one your site then uses depends on the setting of the variable by your environment, so for example you could set ASPNETCORE_ENVIRONMENT` to production or stage as part of your deployment to azure, and then the relevant file will be used when the site runs.

    n.b Production is the default if nothing is set

    The shorter answer for what you are asking, if during your development you use a local db put that in appsettings.development.json for live / stage you would put it in the relevent file, and set the environmental variable on the site when it runs.


    Info on the environmental variable setup https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-6.0

Please Sign in or register to post replies

Write your reply to:

Draft