I have a ASP.Net 5 application where i have some configuration values stored in config.json
file. my config.json file is something like this.
{
"AppSettings": {
"SiteEmailAddress": "[email protected]",
"APIKey": "some_api_key"
}
}
I am setting up the config.json file to use in Startup.cs
file like this.
public static IConfigurationRoot Configuration;
public Startup(IApplicationEnvironment appEnv) {
var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
}
And accessing the config settings like this..
var email = Startup.Configuration["AppSettings:SiteEmailAddress"];
Earlier in ASP.Net we can use the Web.Config
file to store these Application Settings and override them in App Settings in Azure App Settings section and that works with out any issues. But how can i do the same thing in ASP.Net 5 app.
How can i override the configuration values in config.json file in the App Settings section in Azure.
When you add, remove, or edit app settings, App Service triggers an app restart. For ASP.NET and ASP.NET Core developers, setting app settings in App Service are like setting them in <appSettings> in Web. config or appsettings. json, but the values in App Service override the ones in Web.
Connection String within the Azure Portal Open the Azure Portal via https://portal.azure.com. Navigate to the Azure App Service Web App within the portal. Under Settings open up the Configuration option. The Connection strings section can be used to manage the settings for the application.
The appsettings. json file is generally used to store the application configuration settings such as database connection strings, any application scope global variables, and much other information.
Assuming you have appsettings.json, you could add another file appsettings.{Environment}.json, ie appsettings.Production.json. Only settings, defined in the production file would override settings in the appsettings.json. Now, add the following to the constructor of Startup
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true);
Next, you should go to launchSettings.json where all servers are defined and update environment variable to Production. For example,
"web": {
"commandName": "web",
"environmentVariables": {
"Hosting:Environment": "Production"
}
Now deploy to azure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With