C# 以编程方式启动Azure网站槽
我正在尝试使用C#代码序列以编程方式为Azure网站启动一个插槽。 我已尝试使用以下代码:C# 以编程方式启动Azure网站槽,c#,azure,azure-web-app-service,C#,Azure,Azure Web App Service,我正在尝试使用C#代码序列以编程方式为Azure网站启动一个插槽。 我已尝试使用以下代码: public async Task StartWebsiteSlot() { var subscriptionId = "{my Azure subscription id}"; var certPath = "{my full path to the Azure management certificate}"; var certificate = new X509Certificat
public async Task StartWebsiteSlot()
{
var subscriptionId = "{my Azure subscription id}";
var certPath = "{my full path to the Azure management certificate}";
var certificate = new X509Certificate2( certPath, {my password});
var httpHandler = new WebRequestHandler();
httpHandler.ClientCertificates.Add(certificate);
httpHandler.ClientCertificateOptions = ClientCertificateOption.Automatic;
var url = "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{groupname}/providers/Microsoft.Web/sites/{site name}/start?api-version=2015-08-01";
var postContent = new StringContent( String.Empty );
using (var client = new HttpClient(httpHandler))
{
var response = await client.PostAsync(url, postContent);
}
}
调用返回“Unathorized”。
我知道该证书没有问题,因为我正在将其与WebManagementClient一起使用以交换部署插槽
我应该如何访问特定的Azure管理REST API?Nuget软件包允许您从C#管理网站。加载nuget包后,可以使用该方法启动网站。有关用法,请参见下文
yourwebsiteclient.Websites.RestartAsync
希望这有帮助
看看这个问题:
它使用了neolursa建议的Azure管理库
棘手的部分是配置SSL:David Ebbo目前有一个解决方案
必须用StartSiteAsync或StartSiteSlotAsync替换RestartAsync调用。RestartAsync对我不起作用,我在问这个问题之前已经尝试过了(这就是我尝试直接访问Azure Management REST API的原因)。您有工作代码示例吗?