0

We're trying to leverage Azures deployment slots for an Umbraco site we've built.

By default Umbraco uses a DSN defined in the connectionStrings sections of the web.config and we want it to use the connection string for the deployment slot it's sitting in.

What we've tried

Azure deployment slots put all defined app settings (and connection strings) into environment variables and to access them we can use Environment.GetEnvironmentVariable() which works but there doesn't seem to be a way to tell Umbraco to do this.

So in OnApplicationInitialized() (in /App_Code/Core/UmbracoAppStart.cs) we loaded the connectionstring section from the web.config, grabbed the connstr from env vars, added the DSN to the connectionstring section and saved. The correct connection string is grabbed and stored but this seems to recycle the app (due to a web.config change) and thus we just get timeouts. (Or Umbraco XML cache errors, or it takes 20 mins to load the page).

I know you can store the appsettings and connectionstrings sections in separate files. But the file attribute (that doesn't cause a recycle if the referenced file is changed) doesn't work on the connectionStrings section - only the configSource attribute and that DOES recycle if changed.

(from: ASP.NET web.config: configSource vs. file attributes)

Help

Has anyone found a way around this? We simply need to get Umbraco to use the deployment slot connection string - not the one in webconfig.

I'm even willing to copy and paste blindly at the moment without understanding how it works - and I hate doing that :). But that's what happens when people agree when the client wants to go live just before Christmas...

Jag
  • 723
  • 8
  • 21

1 Answers1

2

You don't need to do any code to use Azure connection string or the app settings. Just give them the same keys/names as you have on your web.config and they will be used instead.

So if you have this on your web config:

<add name="umbracoDbDSN" connectionString="Server={server};Initial Catalog={db};Persist Security Info=False;User ID={user};Password={password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=300;" providerName="System.Data.SqlClient" />

Your slot configuration should be this:

enter image description here

To replace an app setting just use the same key. So for this:

<add key="umbracoUseSSL" value="false" />

You'd use this: enter image description here

If you want the setting to be slot specific you have to activate the Slot setting checkbox.

Mario Lopez
  • 1,405
  • 13
  • 24
  • Wow, I feel stupid now. I must admit I never tried adding the connstr to azure using the same name... Still can't believe I haven't come across this in my googling the last couple of days. It works though, thanks so much Mario :) – Jag Dec 01 '17 at 10:02
  • Ha, no problem. Everything is easy when you know it. – Mario Lopez Dec 01 '17 at 10:17