问题描述
我正在尝试使用以下请求仅更新一个应用程序设置.我的设置正在正确更新,但是所有其他应用程序设置都消失了.我仅在其中看到一个设置,该设置具有我尝试更新的正确更新值.我不想丢失或更改所有其他应用程序设置.
I am trying to update only one application setting using below request. My setting is getting updated properly, but my all other application settings are vanished. I see only one settings there with the correct updated value which I tried to update. I do not want to loose or change all other application settings.
我在这里想念的是什么?我在做什么错了?
What am I missing here or what is wrong I am doing?
我正在关注以下给出的文章:
I am following the below given article:
https://docs.microsoft.com/en -us/rest/api/appservice/webapps/updateapplicationsettings
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/config/appsettings
我正在使用他们的在线工具发送请求: https://docs.microsoft.com/zh-cn/rest/api/appservice/webapps/updateapplicationsettings
I am using their online tool to send the request:https://docs.microsoft.com/en-us/rest/api/appservice/webapps/updateapplicationsettings
由于我使用的是在线工具,因此它会生成授权令牌.但是我想以编程的方式来做.如果我能获得示例代码来生成令牌并更新应用程序设置,那就太好了.
Since I am using the online tool it is generating the authorization token. But I want to do programmatically. It would be great if I can get the sample code to generate the token and to update application settings.
推荐答案
我会重现您的问题,如果您要更新应用程序设置,则需要写下所有应用程序设置,否则它将被一个应用程序设置覆盖.
I reproduce your problem and if you want to update application setting, you need to write down all the application settings, otherwise it will be overridden by the one application setting.
准备工作:
1. Register an App registration
并获取appid和appsecret.请参阅此文章.
1.Register an App registration
in Azure Active Directory and get appid and appsecret. Please refer to this article.
2.将注册的应用添加到Access control
下的Role assignments
.
2.Add the registered app into Role assignments
under Access control
.
这是您可以参考的C#代码示例.
Here is C# code sample you could refer to.
var appId = "xxxxxxxxxxxxxxxxxxxx";
var secretKey = "xxxxxxxxxxxxxxxxxxxx";
var tenantId = "xxxxxxxxxxxxxxxxxxx";
var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
ClientCredential clientCredential = new ClientCredential(appId, secretKey);
var tokenResponse = context.AcquireTokenAsync("https://management.azure.com/", clientCredential).Result;
var accessToken = tokenResponse.AccessToken;
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
var baseUrl = new Uri($"https://management.azure.com/");
var requestURl = baseUrl +
@"subscriptions/xxxxxxxxxxxxxxxxxxx/resourceGroups/xxxxxx/providers/Microsoft.Web/sites/xxxxxx/config/appsettings?api-version=2016-08-01";
string body = "{\"kind\": \"webapp\",\"properties\": {\"WEBSITE_NODE_DEFAULT_VERSION\": \"6.9.1\",\"aaa\": \"bbb\"}}";
var stringContent = new StringContent(body, Encoding.UTF8, "application/json");
var response = client.PutAsync(requestURl, stringContent).Result;
}
结果如下:
这篇关于更新应用程序设置:Azure功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!