codeMonkey
codeMonkey

Reputation: 4815

.NET Framework 4.8 UserSecretsConfigBuilder "Expand" (v2.0) and "Token" (v3.0) modes don't replace all tokens

I am using Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder and trying to update tokens in my web.config file. Documentation mentions that mode="Expand" (update: and now mode="Token" in v3.0) in the builders config should operate on raw XML of web.config file and replace any tokens it finds with pattern ${...}; however this is not the case in my experience.

Here is my config section:

<configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />      
</configSections>
<configBuilders>
    <builders>
        <add name="Secrets" userSecretsFile="~\secrets.xml" mode="Expand" optional="true" type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </builders>
</configBuilders>

However, down below, I have a token for my content security policy that is not getting replaced when I run the app:

<system.webServer>
    <httpProtocol>
        <customHeaders>
            <add name="Content-Security-Policy" value="${ContentSecurityPolicy}" />
        </customHeaders>
    </httpProtocol>
</system.webServer>

Likewise, this is replacing the tokens neither in my system.serviceModel nor system.net sections.

Is the documentation simply wrong, and it still only operates on appSettings and connectionStrings? That would be a huge bummer.

Upvotes: 4

Views: 913

Answers (0)

Related Questions