2
votes

I'm playing around with a small ASP.NET Core 1.1 app which I have published. Now I'm following the documentation with regards to using appsettings*.json and environment variables. So I have the following:

appsettings.json
appsettings.Development.json

Each appsettings*.json file has an appropriate "ConnectionStrings:" section:

  "ConnectionStrings": {
    "IdeasDatabase": "Server=tcp:adb.database.windows.net,1433;Initial Catalog=db;Persist Security Info=False;User ID=a_user;Password=apwd;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
  }

So, when I published to begin with to Azure, I used a default connection string in the Publish settings (which was wrong I know), now this is showing in Azure remote settings for the my app:

enter image description here

The above connection string was populated on my first publish in this screen (Publish Wizard):

enter image description here

Now my Production app seems to be using this setting in the above image and not taking the setting from my appsettings.json connection string section.

My appsetting.json file is present on Azure App Service:

enter image description here

I know I can override that Database connection string in the Publish wizard tot the correct string, but shouldn't Azure take the Connection String first from my appsettings.json file which is different from wherever it is storing it on Azure.

2

2 Answers

3
votes

now this is showing in Azure remote settings for the my app:

Azure remote settings stored as environment variables. It has a higher priority than configuration in appsettings.json. If you want to use the settings which configured in appsettings.json at runtime on Azure, you could delete the Azure remote settings from Azure portal or Visual Studio. After that, Azure Web App will use the setting in appsettings.json.

enter image description here

2
votes

Use the environment variables or another secure mechanism. Storing the production connection string in a file is insecure.