Programming, error messages and sample code

How to use Environment Variable that set in your Account

Programming, error messages and sample code > ASP.NET

How to set Environment Variable in your Account   Since the Environment Variable is set on your Application Pool level, you are able to read it from anywhere in your ASP.NET Core APP using Environment Class (the default environment name is "Production" in your account)   For instance:   default code to read connection string from appsettings.json in Startup.cs
services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
now, you can change it to this
services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Environment.GetEnvironmentVariable("DefaultConnection")));
  Another sample
using System;
...

var apiKey = Environment.GetEnvironmentVariable("apiKey");