I have a password in my appsettings.json (well, secrets.json, really) containing quotation mark. That causes issues, naturally, and I tried to escape it the usual way. However, the rendition into the string as I read in that setting doesn't transform it properly.
The different appsettings.json.
{ "CertPass": "abc"123", ... }
{ "CertPass": "abc\"123", ... }
{ "CertPass": "abc""123", ... }
{ "CertPass": "abc\\\"123", ... }
The Program.cs.
string pass = config.Env<string>("CertPass");
public static class ConfigurationExtensions
{
public static T Env<T>(this IConfiguration self, string key)
=> self.GetSection(key).Get<T>()!;
}
The solution of enclosing it with apostrophes and/or replacing the quotation mark with " didn't work. The string still gets into the application in verbatim state (i.e. with the apostrophes and ampersand).
In my case it's not a connection string. It's just a password for a different purpose (the secret to our certificate stored in a PFX file). That's probably why the solution above won't work.
What do I do?
My (hacky) workaround is (for now) to store the password with a "¤" (whatever this is called) and then replacing it in the code after it's been read. Not pretty nor recommended.