0

The stock web.config contains this entry:

 <configBuilders>
    <builders>
      <add name="SitecoreAppSettingsBuilder" mode="Strict" prefix="SITECORE_APPSETTINGS_" stripPrefix="true"
        type="Sitecore.Configuration.FlexibleEnvironmentConfigBuilder, Sitecore.Kernel"/>
      <add name="SitecoreConnectionStringsBuilder" mode="Strict" prefix="SITECORE_CONNECTIONSTRINGS_" stripPrefix="true"
        type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=1.0.0.0, Culture=neutral"/>
    </builders>
  </configBuilders>

However, if you add a connection string to an app service configuration setting, as documented here, the connection strings will in fact be prefixed with a value like SQLCONNSTR_ or SQLAZURECONNSTR_, depending on a user selection when entering the value. This is documented here. Is there a reason why SItecore ships with the non-standard value in Web.config, and is there an approved or standard way of setting this in Azure?

I'm inclined to simply update the <builders> prefix value, but curious if there are other standard approaches here.

3
  • I think the reason was to provide a platform agnostic configuration builder, that would work for all platforms that support environment variables, and not just for Azure PaaS. With Azure PaaS app services though, I usually like to rely on the native Azure App Services capabilities and use the connection strings names without prefix for their respective settings keys (ie. "master", "web",...). Oct 28, 2022 at 1:21
  • Don't they get prefixed then with the connection string type? E.g. SQLCONNSTR_master. (See learn.microsoft.com/en-us/azure/app-service/…). I was thinking I could put "SQLCONNSTR_" in the config builder prefix setting, but that means you need to use that option for things like Solr URLs, which feels a little hackly. Oct 28, 2022 at 14:32
  • 1
    I think this old article explains the extra runtime "magic" that allows the mapping from environment variables to connection strings configuration in ASP.NET applications: azure.microsoft.com/en-us/blog/… Oct 28, 2022 at 15:30

1 Answer 1

0

As Alessandro Faniuolo points out, ASP.NET sites have another mechanism in addition to environment variables to access these settings, so the prefix in Web.config does not need to match what PaaS generates.

Adding a connection string for, say, "web", in the "Configuration" blade "Connection Strings" section will cause it to get mapped by the ConfigurationManager to the "web" database connection string.

See the article he links to above for an explanation of how this works:

For ASP.NET web applications, there is some extra runtime magic that is available as well when using the .NET 4.5 framework.

This "magic" bypasses the environment variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.