简体   繁体   English

如何使用ARM和C#将应用程序部署到Azure?

[英]How to deploy an app to azure using ARM and C#?

I've seen some examples of how to create storage resources using ARM and C#. 我已经看到了一些有关如何使用ARM和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 ac#/Web api app that would be able to deploy another app. 理想情况下,我想拥有一个能够部署另一个应用程序的ac#/ Web api应用程序。 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. 基本上,我想用自己的配置创建同一应用程序的新实例-该过程将由新客户注册我的SaaS触发。 Could someone please give some pointers on how to deal with the above? 有人可以就如何处理上述问题提供一些建议吗? Thanks. 谢谢。

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. 似乎您想以C#代码编程方式将Web应用程序(部署程序包)部署到Azure应用服务Web应用程序,您可以尝试使用Kudu Zip API ,该API允许将zip文件扩展到文件夹中。 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 . 此外,您可以使用Microsoft.Azure.Management.Fluent管理Azure应用程序服务

You could grab the Azure Management Libraries for .Net from Github. 您可以从Github获取.Net的Azure管理库。 Support for Azure App Service is in preview as of v1.2. 从v1.2开始,对Azure App Service的支持处于预览状态。 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 此处显示了很多适用于Windows和Linux风格的Azure App Service的代码示例: 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://docs.microsoft.com/en-us/azure/sql-database/sql-database-design-patterns-multi-tenancy-saas-applications https://docs.microsoft.com/zh-cn/azure/sql-database/sql-database-design-patterns-multi-tenancy-saas-applications中介绍了各种可能性和设计模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM