我正在使用 C# 以编程方式创建和配置 Azure Web Apps。
我已经能够成功创建网络应用程序,并且还配置了其网络托管计划并将其升级为“共享”。但是,我想向我的网络应用程序添加域。
例如,我想将 www.examplesite.com 添加到我的网络应用程序“TestWebApp”中。
我已经在我的程序中使用了以下命名空间:
- 使用 Microsoft.WindowsAzure.Management.WebSites;
- 使用 Microsoft.WindowsAzure.Management.WebSites.Models;
为了实现这一点,我需要哪些具体细节?谢谢!
最佳答案
您可以使用以下代码来管理您的域。
using System;
using Microsoft.WindowsAzure.Management.WebSites;
using Microsoft.WindowsAzure.Management.WebSites.Models;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Azure;
namespace updateWebApp
{
class Program
{
private static WebSiteManagementClient _WebSiteClient;
private static String SubscriptionId = "<your subscription id>";
private static X509Certificate2 cert = new X509Certificate2("E:/path/azure.cer");
private static String webspace = "<your webspace name>";
private static String websitename = "<your web site name>";
static void Main(string[] args)
{
var credential = new CertificateCloudCredentials(SubscriptionId, cert);
_WebSiteClient = new WebSiteManagementClient(credential);
var web = _WebSiteClient.WebSites.Get(webspace, websitename, null).WebSite;
web.HostNames.Add("www.example.com");
var updates = new WebSiteUpdateParameters{
HostNames = web.HostNames,
ServerFarm = web.ServerFarm,
State = web.State
};
_WebSiteClient.WebSites.Update(webspaces, websitename, updates);
System.Console.WriteLine("Press ENTER to continue");
System.Console.ReadLine();
}
}
}
这段代码只是将禁用 ssl 的域“www.example.com”添加到您的网络应用程序中。为了使用我的代码,您需要执行以下操作。
创建证书并将其上传到 Azure 经典门户。
创建 DNS 记录,如 here 中所述。 .
如果您想要启用 ssl,您还需要为 WebSiteUpdateParameters 设置 HostNameSslStates。为此,您需要指纹和 VirtualIp。
关于c# - 使用 C# 管理 Azure Web 应用程序的域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37520798/