0

I have a legacy web application in .NET 4.8 (VB). I need to add secret file and read value from it.

In web.config and I added the following:

<configuration>
  <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" userSecretsId="0c09afe4-6f59-4293-962b-2aad41d88772" type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=1.0.0.0, Culture=neutral" />
        </builders>
    </configBuilders>

And then created secret.xml file:

 <?xml version="1.0" encoding="utf-8"?>
    <root>
      <secrets ver="1.0">
         <secret name="Value1" value="someexampletext" />
     </secrets>
    </root>

Then I'm trying to get this value:

Dim s2 As String = ConfigurationManager.AppSettings("Value1")

But get Nothing (the same as null).

I think because I added it to configuration in web.config it I can read it using ConfigurationManager, correct?

Did I miss something?

1 Answer 1

1

Adding key to appSettings in web.config resolves problem:

<appSettings configBuilders="Secrets">
    <add key="Value1" value=""/>
 </appSettings>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.