16

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

Daniel van Heerden
  • 836
  • 1
  • 7
  • 25

2 Answers2

14

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.

juunas
  • 54,244
  • 13
  • 113
  • 149
  • 1
    Is the swap of the Variables immediate? I tried it with both slot settings, but it doesnt apply the new setting after being swapped. If I subtlety edit the setting after deployment it suddenly applies, but it doesn't happen during the swap. – Daniel van Heerden Jun 15 '16 at 22:56
6

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.

Daniel van Heerden
  • 836
  • 1
  • 7
  • 25
  • 1
    Maybe the REST-API helps to "see what was in this mysterious bag" by having a look in the current app settings? E.g. https://mysite.scm.azurewebsites.net/api/settings – syr Jan 30 '17 at 11:35
  • Yeah, as I said above, the mysterious bag isn't really a mystery. It is just whatever is on your applications settings. It just royally confused me that the blades settings actually swapped with the website binaries. I wouldn't have been confused if everything was slot settings, but because they aren't and my swap was done using a power shell script during a deployment pipeline, I didn't see the swap warnings you get when doing it manually. It was these warnings that actually helped me understand what was going on :) – Daniel van Heerden Sep 18 '17 at 04:22
  • I still find this too vague :-( i think MS could do a better job documenting these things, i am getting tired of azure fast because of this :-( – Zorkind Jul 12 '18 at 15:24
  • @Zorkind, I agree. Once you get used to it it is obvious. But you need to think of the slots as separate computers with different sets of settings on them. When they swap the settings go with them, it is just their IP addresses that are swapped. However you can force a particular setting value to always stay on the named slot (for example, "live" or "warm-up") by making it a slot setting i.e ticking the slot setting checkbox. – Daniel van Heerden Aug 14 '20 at 02:17