Can I send a key-value pair to Azure App Config through my c# code?
Yes, you can send a key-value from Controller Action Method and create a key-value pair in Azure App Configuration.
- As mentioned in the MSDoc, I have used
SetConfigurationSetting to create a Key-Value pair.
My appsettings.json file:
"AppConfig": "Endpoint=https://harshuappconfig.azconfig.io;Id=RoKQ;Secret=****************"
My Program.cs file:
var appConfig = builder.Configuration["AppConfig"];
builder.Services.AddAzureAppConfiguration();
My Controller ActionMethod:
private readonly IConfiguration config;
private readonly ConfigurationClient configClient;
public HomeController(IConfiguration myconfig, ILogger<HomeController> logger)
{
_logger = logger;
config = myconfig;
var connectionString = config["AppConfig"];
configClient = new ConfigurationClient(connectionString);
}
public IActionResult Index()
{
var KVPair = JObject.Parse(@"{""Name"":""Harshitha"",""SurName"":""Veeramalla""}");
foreach (var kv in KVPair)
{
Console.WriteLine($"Key '{kv.Key}' updated value '{kv.Value}' in Azure App Config.");
var setting = new ConfigurationSetting(kv.Key, kv.Value.ToString());
configClient.SetConfigurationSetting(setting);
}
return View();
}
- Here I am sending the JSON object in a string.
Output:


SetConfigurationSetting. Refer this MSDoc once.Imagea key-value pair as json through my controller, can you share a sample json once.{"key":"value"}. So my controller basically accepts aDictionary<string, string>