Reputation: 569
I have added an app setting in Azure for my Web Application that I named "SecretKey". When I try to access it in my asp.net mvc app, the key returns null.
var key = Environment.GetEnvironmentVariables("SecretKey");
I've tried to look up information and I can't find if there is anything I need to do beyond adding the key in Azure. Why is it not able to access it? Is there something I need to do elsewhere in my application to get it to access it?
Upvotes: 0
Views: 285
Reputation: 222700
You can access it as follows,
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
and use it as
public void ConfigureServices(IServiceCollection services)
{
var connection = Configuration.GetConnectionString("SecretKey");
services.AddDbContext<ShelterPZ_DBContext>(options => options.UseSqlServer(connection));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
}
Upvotes: 1
Reputation: 306
check https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1
in your example your are reading env vars but not app settings
Upvotes: 0