I have a project with an appsettings.Development.json file, to which I've added the following section:
"ConnectionStrings": {
"Database one": "<Host...;Username=...;Password=...;etc.>"
}
When I search the internet for instructions on how to encrypt the ConnectionStrings section, I keep finding instructions that try to call functions that my IDE (VSCode) doesn't recognize (it doesn't even suggest that I must download a NuGet or import a using), which leads me to believe that it's all outdated, just as this person did. But what confuses me is that even the Microsoft documentation (see this link and this link), which is supposed to be up to date, is instructing me to use the functions that VSCode doesn't recognize, such as OpenExeConfiguration, SectionInformation, IsProtected, and ProtectSection.
Below is my best attempt at creating working code from the examples I've found, but it doesn't work yet because VSCode is still unable to recognize SectionInformation and ProtectSection:
public void ProtectSection(ConfigurationManager cManager)
{
try
{
var section = cManager.GetSection("ConnectionStrings") as ConfigurationSection;
if (!section.SectionInformation.IsProtected)
{
section.ProtectSection("ConnectionStrings");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}