azure - 在动态创建的 Web 应用服务中添加自定义域

标签 azure azure-web-app-service

我已经使用 REST API 创建了 azure Web 应用程序。是否有任何选项可以使用rest api 自定义域映射?.

通过下面的链接,我创建了新的网络应用服务。

https://learn.microsoft.com/en-us/rest/api/appservice/webapps/createorupdate

最佳答案

正如 @4c74356b41 提供的,您可以使用 Web Apps - Create Or Update Host Name Binding实现你想要的。我在我的网站上测试过,效果很好,您可以引用以下步骤。

1.转到您在门户中创建的 Web 应用程序,并向在 Azure AD 中注册的应用程序添加权限

enter image description here

2.转到自定义域的 DNS 配置 UI,然后按照 instructions 进行操作。 。

enter image description here

3.您可以按照以下代码操作。

注意:此处的 hostNameBindings 名称是自定义域 DNS 区域中的整个 CNAME,例如 joey.example.com

var appId = "xxxxxxxxxxxxxxxxx";
var secretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
var tenantId = "xxxxxxxxxxxxxxxxxxxxxxxx";
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/xxxxxxxxxxxx/providers/Microsoft.Web/sites/xxxxxxxxxx/hostNameBindings/xxxxxxxxxxxxxx?api-version=2016-08-01";
    string body = "{\"properties\": {\"azureResourceName\": \"joey\"}}";
    var stringContent = new StringContent(body, Encoding.UTF8, "application/json");
    var response = client.PutAsync(requestURl, stringContent).Result;
}

输出:

enter image description here

关于azure - 在动态创建的 Web 应用服务中添加自定义域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52037918/

相关文章:

Azure应用服务-无法将日志存储在Azure存储中

multithreading - 将并发客户端调用同步到 azure 移动服务

api - 是否可以通过管理/资源管理 API 为 Azure 网站启用 Always On?

sql-server - SQL Server Data Tools 在轻度 DAX 计算中崩溃

路径中的 Python Azure 应用程序 404

azure - 我可以将 Azure Webjobs 部署为 IoT Edge 模块吗?

将 Azure Web API 限制为仅 API Manager

c# - 如何在 Azure Functions 中使用 NuGet 包?

azure - 有关在 Azure 中布局资源组的问题

azure - Azure Webapp 上的 Kudu 导致 "Invalid URI: The hostname could not be parsed."异常