[英]How to get and set Azure app service configuration settings from C# code?
I have an Azure app service.我有一个 Azure 应用程序服务。 And I have C# application.
我有 C# 申请。 I want to get and set configuration settings (appsettings) for my Azure app service from my C# application.
我想从我的 C# 应用程序获取和设置我的 Azure 应用程序服务的配置设置 (appsettings)。
I can do it from PowerShell using az webapp config appsettings list
and az webapp config appsettings set
.我可以使用
az webapp config appsettings list
和az webapp config appsettings set
。 I want to achieve the same from C#.我想从 C# 实现相同的目标。
My current solution is to launch PowerShell from C# (using new Process()
) and use az webapp
.我当前的解决方案是从 C# 启动 PowerShell(使用
new Process()
)并使用az webapp
。 That is ugly, errors are hard to catch, and it is awkward to get to run on both Windows and Linux.这很丑陋,很难发现错误,而且很难在 Windows 和 Linux 上运行。
I have looked at the NuGet package Microsoft.Azure.Management.Fluent .我看过 NuGet package Microsoft.Azure.Management.Fluent 。 It has a method IWebAppBase .
它有一个方法IWebAppBase 。 GetSettings which lets me read the settings.
GetSettings让我读取设置。 But I can find no way to change the settings.
但是我找不到更改设置的方法。 The NuGet package says that it is being phased out, but I cannot find a replacement package for managing app services.
NuGet package 说它正在被淘汰,但我找不到用于管理应用程序服务的替代品 package。
Is there a nice NuGet I should use?我应该使用一个不错的 NuGet 吗?
You will have to use the SDK to do this.您将必须使用 SDK 来执行此操作。
var credentials = SdkContext.AzureCredentialsFactory
.FromServicePrincipal("",
"",
"",
AzureEnvironment.AzureGlobalCloud);
RestClient restClient = RestClient
.Configure()
.WithEnvironment(AzureEnvironment.AzureGlobalCloud)
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.WithCredentials(credentials)
.Build();
var _websiteClient = new WebSiteManagementClient(restClient);
// get
var configs = await _websiteClient.WebApps.ListApplicationSettingsAsync("RG", "WEBAPP");
// add config
configs.Properties.Add("newkey", "newValue");
// update
var result = await _websiteClient.WebApps.UpdateApplicationSettingsAsync("RG", "WEBAPP", configs);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.