We are trying to read environment variables in our .NET Core 3 web service.
If I run this service locally I can debug the builder.Configuration and it shows all the variables regardless if they are set as system or user variables. But, after deployment to our server, it no longer sees ANY of them, no matter if they are set as user or system environment variables.
We really desire to set them under the User context of the Service Account that the web app is running under and need this to work as no person logging into the system would be able to view them unless they had logged in using the service account credentials.
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
builder.Configuration
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile($"appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env}.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables(prefix: env);
Log.Debug($"Reading environment variable {env}-adm.s_id--" + builder.Configuration[env + "-adm.s_id"]);
Log.Debug($"Reading environment variable {env}-enc.s_id--"+ builder.Configuration[env + "-enc.s_id"]);
Log.Debug($"Reading environment variable {env}-srv.s_id--"+ builder.Configuration[env + "-srv.s_id"]);
Log.Debug($"Reading environment variable {env}-sett.s_id--" + builder.Configuration[env + "-sett.s_id"]);
Log.Debug($"Reading environment variable {env}-trans.s_id--" + builder.Configuration[env + "-trans.s_id"]);
Even using code like this returns NO values:
var adm_s_d = Environment.GetEnvironmentVariable(env + "-adm.s_id");
Log.Debug($"{env}-adm.s_id=" + adm_s_id);
Any help here could be appreciated.