Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change values in appSettings.json file based on environment

I am building API in .net core project and have to store some key value pairs in appSettings.json file for jwt token. For example i need to store valid issuer and valid audience. For development i have my appSettings.json file as below:

`{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "jwt": {
    "JwtIssuer": "https://localhost:44332/",
    "JwtAudience": "https://localhost:44332/",
    "JwtSecretKey": "my super secure key"
  }
  "AllowedHosts": "*"
}`        

For development environment this is fine but when i will have to deploy to say azure, do i need to change these URLs manually here in appSettings.json file or is there any other efficient way to manage these URLs that automatically gets updated based on environment.

like image 969
Muhammad Ali Avatar asked Oct 14 '25 14:10

Muhammad Ali


1 Answers

The default of ConfigurationBuilder is looking for appsettings.<EnvironmentName>.json file, so based on the environment that you are working with

when you are in IIS Express you are in Development and when you deploy your application your environment is Production. This is why you need appsettings.Production.json

like image 86
Saeed Gholamzadeh Avatar answered Oct 17 '25 20:10

Saeed Gholamzadeh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!