1

I'm trying to programmatically start a slot for an Azure website using a C# code sequence. 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". I know the certificate is ok because I'm using it with the WebManagementClient to swap deployment slots.

How should I access that specific Azure management REST API?

Thomas
  • 24,234
  • 6
  • 81
  • 125
Dan
  • 1,927
  • 2
  • 24
  • 35

3 Answers3

1

this Nuget package lets you manage the websites from C#. Once you get the nuget package loaded, you can use the RestartAsync() method to start the website. See below for the usage.

yourwebsiteclient.Websites.RestartAsync

Hope this helps!

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

neolursa
  • 432
  • 2
  • 6
  • RestartAsync does not work for me, I've tried it before asking this question (it's the reason I've tried to directly access the Azure Management REST API). Do you have a working code sample? – Dan Dec 08 '15 at 07:14
1

David Ebbo has a solution for this at https://github.com/davidebbo/AzureWebsitesSamples/ One has to replace the RestartAsync call with StartSiteAsync or StartSiteSlotAsync.

Dan
  • 1,927
  • 2
  • 24
  • 35
0

Look at this question : Change Azure website app settings from code.

It used the Azure Management Libraries as suggested by neolursa.

The tricky part is to configure SSL : Using Azure Management Libraries from Azure Web Jobs

Community
  • 1
  • 1
Thomas
  • 24,234
  • 6
  • 81
  • 125