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?
Adding key to appSettings in web.config resolves problem:
<appSettings configBuilders="Secrets">
<add key="Value1" value=""/>
</appSettings>