Closed jjrobert65 closed 5 months ago
A config builder can inject information into any configuration section that it knows about. (Out of the box, that's AppSettings and ConnectionStrings... but you can create section handlers to work with other config sections if needed.) So just declaring a configuration builder doesn't automatically get you where you want because the builder doesn't know where to put it's settings.
Long story short - you need to put a configBuilders="Secrets"
attribute on your <appSettings>
section to tell the 'Secrets' config builder to apply it's values to the appSettings section. Then you should see your secret values show up in ConfigurationManager.AppSettings.
Thanks so much! Now I have to go re-read all the articles and see how many times I missed that!
-Jeff
This is almost certainly a misunderstanding or typo on my part but I haven't been able to figure out how to access the user secret I've set up from my code.
I have a .NET Framework 4.8 Web API project.
I right-clicked into "Manage User Secrets" in Visual Studio and let it install Microsoft.Configuration.ConfigurationBuilders.UserSecrets and update my Web.config:
Here are the important bits of my Web.config:
and the secrets.xml file exists and has one secret:
In one of my controllers I've tried to do this:
but I always get null.
I thought maybe it was an issue with the key name or something but when I loop over ConfigurationManager.AppSettings.Keys as in your examples and dump what's there, I only get the four values in the portion of Web.config:
Am I wrong to expect to read these from Configuration.AppSettings ? Am I missing part of the glue?
Thanks, -Jeff