[英]Programmatically start an Azure website slot
I'm trying to programmatically start a slot for an Azure website using a C# code sequence. 我正在尝试使用C#代码序列以编程方式启动Azure网站的广告位。 I've tried to use the following code: 我尝试使用以下代码:
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);
}
}
The call returns "Unathorized". 呼叫返回“ Unathorized”。 I know the certificate is ok because I'm using it with the WebManagementClient to swap deployment slots. 我知道证书是可以的,因为我将其与WebManagementClient一起使用以交换部署插槽。
How should I access that specific Azure management REST API? 我应该如何访问该特定的Azure管理REST API?
this Nuget package lets you manage the websites from C#. 这个 Nuget软件包使您可以从C#管理网站。 Once you get the nuget package loaded, you can use the RestartAsync() method to start the website. 加载nuget程序包后,可以使用RestartAsync()方法启动网站。 See below for the usage. 用法请参见下文。
yourwebsiteclient.Websites.RestartAsync
Hope this helps! 希望这可以帮助!
https://www.nuget.org/packages/Microsoft.WindowsAzure.Management.WebSites/ https://www.nuget.org/packages/Microsoft.WindowsAzure.Management.WebSites/
https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.management.websites.iwebsiteoperations.restartasync(v=azure.11).aspx https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.management.websites.iwebsiteoperations.restartasync(v=azure.11).aspx
David Ebbo在https://github.com/davidebbo/AzureWebsitesSamples/上有一个解决方案,必须用StartSiteAsync或StartSiteSlotAsync代替RestartAsync调用。
Look at this question : Change Azure website app settings from code . 看一下这个问题: 从代码更改Azure网站应用程序设置 。
It used the Azure Management Libraries as suggested by neolursa. 它使用了Neolursa建议的Azure管理库。
The tricky part is to configure SSL : Using Azure Management Libraries from Azure Web Jobs 棘手的部分是配置SSL: 使用Azure Web Jobs中的Azure管理库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.