Home > Blockchain >  What is flow of web.config transformations in asp.net core
What is flow of web.config transformations in asp.net core

Time:12-03

In my application I hold my connection strings in appsettings.json... I don't have default web.config file.. my purpose is to learn how to manage environments in asp.net core. If I will make web.config transform it will automatically change appsettings.json?

CodePudding user response:

As far as I know, the web.config will not change the appsettings.json. But the appsetting.json contains an environment feature.

Asp.net core has JsonConfigurationProvider enabled by default.

Form official document:

The default JsonConfigurationProvider loads configuration in the following order:

appsettings.json appsettings.Environment.json : For example, the appsettings.Production.json and appsettings.Development.json files. The environment version of the file is loaded based on the IHostingEnvironment.EnvironmentName. For more information, see Use multiple environments in ASP.NET Core. appsettings.Environment.json values override keys in appsettings.json. For example, by default:

In development, appsettings.Development.json configuration overwrites values found in appsettings.json. In production, appsettings.Production.json configuration overwrites values found in appsettings.json. For example, when deploying the app to Azure. If a configuration value must be guaranteed, see GetValue. The preceding example only reads strings and doesn’t support a default value.

Using the default configuration, the appsettings.json and appsettings.Environment.json files are enabled with reloadOnChange: true. Changes made to the appsettings.json and appsettings.Environment.json file after the app starts are read by the JSON configuration provider.

This means if you set the environment variable by using web.config or server's environment variable, this provider will load the appsttings.environment.json's value and these value will override the appsettings.json to achieve the transform like old web.config.

  • Related