简体   繁体   English

如何从 C# 代码获取和设置 Azure 应用服务配置设置?

[英]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 listaz 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 来执行此操作。

libs:库:

  • Microsoft.Azure.Management.AppService.Fluent Microsoft.Azure.Management.AppService.Fluent
  • Microsoft.Azure.Common Microsoft.Azure.Common
  • Microsoft.Azure.Management.Fluent Microsoft.Azure.Management.Fluent

you will have to do something like this你将不得不做这样的事情

    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.

相关问题 从 Azure App Configuration Store 获取 Value,其中 content-type 在 C# 中设置为 application/json - Get Value from Azure App Configuration Store where the content-type is set to application/json in C# 无法从 Azure App 服务配置应用程序设置中读取 Azure SignalR 连接字符串 - Unable to read Azure SignalR Connection String from Azure App Service Configuration Application Settings 如何从 Azure 管道中的 Azure 应用服务获取价值 - How to get value from Azure App Service from Azure pipeline 如何从 .Net Frame Asp.Net 应用程序中的 Azure App Service 配置获取连接字符串? - How do I get a connection string from Azure App Service configuration in a .Net Frame Asp.Net application? 无法更新 Azure App 中的配置设置 - Unable to Update Configuration Settings in Azure App 如何将连接字符串存储在 Azure Vault 和 map 中返回到 Azure Web App 中的配置设置? - How to store connection string in Azure Vault and map it back to the configuration settings in Azure Web App? 如何从 Azure Web 应用服务部署中心获取信息 - How to get info from Azure Web App Service Deployment Center 如何从 Spring 引导获取具有特定 label 的 Azure 应用程序配置功能标志的值? - How to get the value of Azure App Configuration Feature Flag with specific label from Spring boot? 如何从github部署到Azure应用服务 - How to Deploy from github to Azure App Service 在 Azure 应用程序服务上运行的 WCF 服务的 SSL 设置出现问题 - Problem with SSL settings for WCF service running on Azure app service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM