How do I set json file(json file's path) to a value in Azure App settings?
I am adding Firebase SDK to the server.
I defined "/my-json-file.json" as GOOGLE_APPLICATION_CREDENTIALS key's value.
Azure App Configuration
=> Configuration Explorer
Section.Check the below workaround for creating and consuming JSON key-values
In Azure Portal
=> App Configurations
=> Create
application/json
content type.We can create JSON key-values from Azure portal, Azure CLI or even you can create a json file and import values.
Here I have created from portal => App Configuration => Configuration Explorer
Consume JSON values in WebApp
Create ASP. Net Core App, navigate to the project root directory and run the below command to add the UserSecretID
dotnet user-secrets init
Install the Microsoft.Azure.AppConfiguration.AspNetCore
NuGet Package
My Program.cs
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("AppConfig");
builder.Host.ConfigureAppConfiguration(builder =>
{
builder.AddAzureAppConfiguration(connectionString);
})
.ConfigureServices(services =>
{
services.AddControllersWithViews();
});
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
My Index.html of Home Controller
@{
ViewData["Title"] = "Home Page";
}
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
<style>
body {
background-color: @Configuration["Settings:BackgroundColor"]
}
h1 {
color: @Configuration["Settings:FontColor"];
font-size: @Configuration["Settings:FontSize"]px;
}
</style>
<h1>@Configuration["Settings:Message"]</h1>
I have set Background color as yellow in JSON values, you can see it is applied.
Output:
Refer the official MSDoc for binding hierarchical configuration data.