1

I've seen some examples of how to create storage resources using ARM and C#. I'm assuming that the same is possible for apps. However, I can't find a working example. Ideally I'd like to have a c#/Web api app that would be able to deploy another app. The process should be fully automated. Basically, I'd like to create a new instance of the same app with its own configuration - the process would be triggered by a new customer signing up for my SaaS. Could someone please give some pointers on how to deal with the above? Thanks.

2
  • Hi @bdristan, any updates? Are you able to manage Azure app service and deploy web application (deployment package) to Azure app service web app programmatically in C# code now? Commented Sep 19, 2017 at 7:13
  • Hi Fred Han, I haven't gotten to it yet. However, I think that solutions provided below will work for me. I'll need to tackle the issue in about two months. Commented Sep 22, 2017 at 0:53

2 Answers 2

2

It seems that you’d like to deploy web application (deployment package) to Azure app service web app programmatically in C# code, you can try to use Kudu Zip API that allows expanding zip files into folders. And the following sample code works fine for me, you can refer to it.

//get username and password from publish profile on Azure portal
var username = "xxxxx";
var password = "xxxxxxxxxxxxxxxxxxxx";
var AppName = "{your_app_name}";

var base64Auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}"));
var file = File.ReadAllBytes(@"C:\Users\xxx\xxx\WebApplication1.zip");
MemoryStream stream = new MemoryStream(file);

using (var client = new HttpClient())
{
    client.DefaultRequestHeaders.Add("Authorization", "Basic " + base64Auth);
    var baseUrl = new Uri($"https://{AppName}.scm.azurewebsites.net/");
    var requestURl = baseUrl + "api/zip/site/wwwroot";
    var httpContent = new StreamContent(stream);
    var response = client.PutAsync(requestURl, httpContent).Result;
}

Besides, you can use Microsoft.Azure.Management.Fluent to manage your Azure app service.

Sign up to request clarification or add additional context in comments.

Comments

1

You could grab the Azure Management Libraries for .Net from Github. Support for Azure App Service is in preview as of v1.2. This enables a very intuitive syntax.

var webApp = azure.WebApps.Define(appName)
    .WithRegion(Region.USWest)
    .WithNewResourceGroup(rgName)
    .WithNewFreeAppServicePlan()
    .Create();

There are lots of code samples for both Windows and Linux flavours of Azure App Service shown here: https://github.com/Azure/azure-sdk-for-net/tree/Fluent

There are also some worthwhile reading materials on how to handle data in this kind of scenario; various possibilities and design patterns are covered at https://learn.microsoft.com/en-us/azure/sql-database/sql-database-design-patterns-multi-tenancy-saas-applications

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.