简体   繁体   English

以编程方式启动Azure网站位置

[英]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.

相关问题 以编程方式调用Azure网站时出现401 - 401 when calling Azure website programmatically 以编程方式停止Azure功能并重新启动 - Programmatically Stop an Azure function and start it back again 如何以编程方式在azure网站中创建虚拟应用程序和目录 - How to create a virtual application and directories in azure website programmatically 以编程方式从Azure网站内部检索站点URL - Programmatically retrieve the site URL from inside an Azure website 如何以编程方式创建Azure网站和SQL数据库? - How do I create an Azure Website and SQL Database programmatically? Azure插槽交换:在Azure中配置WCF终结点 - Azure Slot Swapping: Configure WCF endpoint in Azure 如何使用 MsBuild 以编程方式在 IIS(6.0 和 7.0)中停止或启动网站? - How can I programmatically stop or start a website in IIS (6.0 and 7.0) using MsBuild? 在特定时段内屏蔽网站(维护活动) - Block website for a specific time slot(maintainence activity) 如何以编程方式将静态HTML网站上传到Windows Azure网站? - How can I upload a static HTML site to a Windows Azure Website programmatically? Azure 函数:代理 + 部署槽 + 查询字符串参数 - Azure Functions: Proxy + Deployment Slot + Querystring parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM