I have an application, for which I'm trying to read environment variables from the Azure configuration menu. As such:
Then some code to read environment variables:
public static string GetPathString()
{
string targetEnv = Environment.GetEnvironmentVariable("TARGET_ENVIRONMENT");
if (targetEnv.Equals(Environments.Dev))
{
return "/RCHHRATool/";
}
else if (targetEnv.Equals(Environments.Azure))
{
return "/";
}
return "INVALID ENVIRONMENT SET IN ENVIRONMENT VARIABLES";
}
However, what I'm finding is, the values being read into the code when deployed to Azure are still from web.debug.config, which presumably it shouldn't even be looking at considering it should be in release mode in the app service.
How do I read custom environment variables from the app service configuration?
web.config
or appsettings.json
by default. AppSetting
must be same in both Development(local) and Azure App Settings. In Azure AppSettings
My Web.config
<appSettings>
<add key="TARGET_ENVIRONMENT" value="TARGET_ENVIRONMENT Development" />
</appSettings>
HomeController
public static string GetPathString()
{
var appsettings = ConfigurationManager.AppSettings;
var targetEnv = appsettings["TARGET_ENVIRONMENT"];
return targetEnv;
}
public ActionResult Index()
{
var EnvVariable = GetPathString();
ViewBag.EnvVariable = EnvVariable;
return View();
}
Output
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.