I am working on a .NET Core 6.0 "Hello World" app and it'll be deployed as an Azure web service.
I am trying to read value from Azure App Service -> Configuration -> ApplicationSetting -> mykey, but I am not able to access value of mykey
after deploying to app service. I am able to read value of mykey
in local while debugging.
Project type:
I have to read mykey
in Program.cs
. What is the simplest way to read the value of mykey
since it is just a hello world app?
Program.cs
:
using HelloWorldApi.Helpers;
using Microsoft.AspNetCore.Authentication.Certificate;
using Microsoft.AspNetCore.Server.Kestrel.Https;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
var provider = builder.Services.BuildServiceProvider();
var configuration = provider.GetRequiredService<IConfiguration>();
builder.WebHost.ConfigureKestrel(o =>
{
o.ConfigureHttpsDefaults(o =>
{
});
}).ConfigureAppConfiguration((hostContext, builder) =>
{
var settings = builder.Build();
// I tried different ways but not getting value of mykey.
// This code is returning null
var connectionString = configuration.GetValue<string>("mykey");
});
var app = builder.Build();