Ari Roth
Ari Roth

Reputation: 5534

Retrieving Web Site Configuration Settings from Azure for use in a Console App

I'm trying to get the settings and connection strings from an Azure web site for use in an internal console tool. This is proving much more difficult than I would have expected. I'm tempted to start looking into bypassing the C# SDK altogether and just use an HttpClient, but I'm not quite there yet.

This is what I have so far:

var armClient = new ArmClient(new DefaultAzureCredential(), "[My subscription ID]");
var webApp = armClient.GetWebSiteResource(new Azure.Core.ResourceIdentifier("[my resource identifier]"));
var b = webApp.GetAllConfigurationData();
var c = b.First();
Console.WriteLine(c.Name);
Console.WriteLine(c.ConnectionStrings == null ? "null" : c.ConnectionStrings.Count);
Console.WriteLine(c.AppSettings == null ? "null" : c.AppSettings.Count);

What I'm getting is the following:

[the correct name of the website]
null
null

Settings and connection strings definitely exist; I can see them on the config page for the website in Azure Portal.

The (extremely minimal and somewhat placeholderish) documentation for GetAllConfigurationData suggests that multiple calls and iterations may be needed, but I'm not even sure what to do with that.

Anyone have any ideas here? Am I going about this all wrong and there's a better way? The console app is non-negotiable, unfortunately.


EDIT: Adding a screenshot of where in the portal the config settings I'm looking at are. (Highlighted one at the bottom.)

Location in Portal Nav

Also, if it helps, I'm looking for the programmatic equivalent of this Powershell command:

az webapp config appsettings list --name foo --resource-group bar

Upvotes: 0

Views: 610

Answers (1)

vdL
vdL

Reputation: 277

I get a similar non result with "GetAllConfigurationDataAsync" but the code below, using other methods of the WebsiteResource class, works for me:

var armClient = host.Services.GetRequiredService<ArmClient>();
var resource = new ResourceIdentifier(resourceId);
var website = armClient.GetWebSiteResource(resource);
var connectionStrings = await website.GetConnectionStringsAsync();
foreach (var prop in connectionStrings.Value.Properties)
{
    Console.WriteLine($"{prop.Key}:{prop.Value.Value}");
}
var applicationSettings = await website.GetApplicationSettingsAsync();
foreach (var appSetting in applicationSettings.Value.Properties)
{
    Console.WriteLine($"{appSetting.Key}:{appSetting.Value}");
}

Upvotes: 0

Related Questions