Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble with Slot Setting for Azure App Services

I need to understand Slot Application Settings better for Azure App Services. When they apply and how to use them correctly.

I have 2 App Services set up each running 2 slots as below.

  1. Site 1 with slot - building-staging
  2. Site 1 with slot - staging

  3. Site 2 with slot - building-production

  4. Site 2 with slot - production

So for each site, I'd like to be able to put an invalid connectionstring for the build slot in the Application Settings blade so that the site can't be accessed and will just give you basically an error page on the azuerwebsites.net url for that slot.

In my production slot of each I then want to put the correct connectionstring so that once swapped they will work.

I can not get this to work reliably, the settings don't apply when I swap. Should I be marking the connection strings on the production slot as slot settings? Should the original one on the build slot be a slot settings? Do I need some kind of nuget package installed I'm not aware of.

Please help

like image 694
Daniel van Heerden Avatar asked Jun 15 '16 13:06

Daniel van Heerden


2 Answers

If I understood your question correctly, you need to mark them all as slot settings.

App settings and connection strings marked as slot settings will stay on the slot when a swap is done. Any settings/connection strings not marked as slot settings will be swapped with the app.

like image 115
juunas Avatar answered Sep 21 '22 12:09

juunas


The answer to my question was found in this document. (Which if anybody from the Azure team comes accross, should really be linked to from the Configuration for deployment slots section here )

Windows Azure Web Sites: How Application Strings and Connection Strings Work

In a nutshell, you shouldn't use ConfigurationManager to get settings from the Application Settings blade UNLESS you are using .NET 4.5 framework.

If you don't use .NET 4.5 framework you should be using Environment.GetEnvironmentVariable instead.

This tripped me up as I was converting an existing environment of mine over to App Services. I would have loved a big warning somewhere to tell me to make sure of this.

EDIT: So this was not the whole story;

The other part is what is meant by "sticky" and "not sticky" settings in the documentation. I kept finding references to the fact that the settings aren't actually put into your web.config file but rather lives in an in memory property bag accessible to your app. I couldn't find any reference of how I could see what was in this mysterious bag, but the answer it obvious once you know it.

During a swap, any settings on your staging slot is actually copied over to the settings of your production slot, i.e. it actually changes it in the production slots "Application Settings" blade. And whatever is in your slot's Application Settings blade is what is in the in memory property bag.

like image 39
Daniel van Heerden Avatar answered Sep 19 '22 12:09

Daniel van Heerden