2

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.

garfbradaz
  • 3,424
  • 7
  • 43
  • 70

2 Answers2

3

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

Amor
  • 8,325
  • 2
  • 19
  • 21
  • Oh my giddy aunt - why didnt i try that! I presumed there would be a"override azure" flag in the Configuration Builder i was missing and completely overlooked the "Remove" button. – garfbradaz Jun 27 '17 at 13:42
  • 1
    There's a good reason environment wins, sensitve data should not be stored in the .JSON file – RickAndMSFT Jun 27 '17 at 16:02
  • @RickAndMSFT So we are saying then, the Publish command for Production (in the wizard) for connstring and use the Development, Staging variables for our test instances (which link to the appropriate appsetting*.json files)? – garfbradaz Jun 27 '17 at 16:05
  • @RickAndMSFT Ive found this https://blog.elmah.io/configuration-with-azure-app-services-and-aspnetcore which I will have a read of when I get home versus the docs I have bookmarked for you guys (docs..). I like to use the nice MS Docs. It looks like a misinterpretation my end, so i will raise any further questions on the liveFyre stuff. Thanks again Rick. – garfbradaz Jun 27 '17 at 16:12
2

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

RickAndMSFT
  • 20,912
  • 8
  • 60
  • 78