What I am trying to achieve
Hello, I have dotnetcore web Api which is running in Azure App Service server farm. I am trying to read the connection string from app service configuration app settings.
What I have tried so far
Below is how I am trying to read the connection string settings
var configValue = (ConfigurationManager.AppSettings["PNLDBConnectionString"] ?? String.Empty).ToString();
I have added the connection string in app service configuration section as below
As well have added a app settings key as below
But in either way, if I am removing the connection string key from app.config
and deploying; then while trying to run any API endpoint throws below error which essentially means the it's not able to read the said connection string property
Any idea, what I could be missing here? Please suggest.
EDIT:
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key ="Encrypted" value="true"/>
<add key ="PNLDBConnectionString" value="connection string value"/>
</appSettings>
</configuration>
Looking at the Kudu portal, under environment variables I could see the settings as
PNLDBConnectionString = xxxxxxxxxx
APPSETTING_PNLDBConnectionString = xxxxxxxxx
Using, Environment.GetEnvironmentVariable("APPSETTING_PNLDBConnectionString")
did the trick actually. Had to modify the code line a bit like
var configValue = ConfigurationManager.AppSettings["PNLDBConnectionString"]
?? Environment.GetEnvironmentVariable("APPSETTING_PNLDBConnectionString")
?? String.Empty;