【发布时间】:2017-12-28 10:08:46
【问题描述】:
我正在尝试编写一个本地控制台应用程序,它将使用Azure REST API 交换一个 Azure Web 应用程序插槽。使用以下代码,我得到 401(未经授权)响应:
public async Task Swap(string subscription, string resourceGroup, string site, string slot)
{
var client = new HttpClient();
var url =
$"https://management.azure.com/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{site}/applySlotConfig?api-version=2016-08-01";
var data = new {preserveVnet = true, targetSlot = slot};
var message = new HttpRequestMessage
{
RequestUri = new Uri(url),
Method = HttpMethod.Post,
Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")
};
var response = await client.SendAsync(message);
Console.WriteLine(response.StatusCode);
}
我知道我需要输入某种凭据,但我发现的内容似乎适用于使用 Azure AD 进行身份验证的应用程序。这将是一个具有匿名身份验证的可公开访问的网络应用程序。
【问题讨论】:
-
请参阅此处以验证 Azure 资源管理器 API 身份验证:docs.microsoft.com/en-us/azure/azure-resource-manager/…。
标签: c# rest azure azure-active-directory azure-deployment-slots