在 Azure 中创建 ASP.NET Core Web 应用Create an ASP.NET Core web app in Azure

您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

在 Azure 中创建 ASP.NET Core Web 应用Create an ASP.NET Core web app in Azure

本文内容

  1. 先决条件
  2. 创建一个 ASP.NET Core Web 应用
  3. 启动发布向导
  4. 登录 Azure
  5. 创建资源组
  6. 创建应用服务计划
  7. 创建并发布 Web 应用
  8. 更新应用并重新部署
  9. 管理 Azure 应用
  10. 清理资源
  11. 后续步骤

备注

本文将应用部署到 Windows 上的应用服务。This article deploys an app to App Service on Windows. 若要部署到基于 Linux 的应用服务,请参阅在基于 Linux 的应用服务中创建 .NET Core Web 应用To deploy to App Service on Linux, see Create a .NET Core web app in App Service on Linux.

Azure 应用服务提供高度可缩放、自修补的 Web 托管服务。Azure App Service provides a highly scalable, self-patching web hosting service. 本快速入门演示如何将第一个 ASP.NET Core Web 应用部署到 Azure 应用服务中。This quickstart shows how to deploy your first ASP.NET Core web app to Azure App Service. 完成后,将拥有一个资源组,该资源组包含一个应用服务计划和一个部署了 Web 应用程序的应用服务应用。When you're finished, you'll have a resource group that consists of an App Service plan and an App Service app with a deployed web application.

如果还没有 Azure 订阅,可以在开始前创建一个免费帐户If you don't have an Azure subscription, create a free account before you begin.

先决条件Prerequisites

为完成此教程,请安装支持 ASP.NET 和 Web 开发工作负荷的 Visual Studio 2017To complete this tutorial, install Visual Studio 2017 with the ASP.NET and web development workload.

如果已安装 Visual Studio 2017:If you've installed Visual Studio 2017 already:

  • 通过单击“帮助” > “检查更新”,在 Visual Studio 中安装最新的更新。Install the latest updates in Visual Studio by clicking Help > Check for Updates.
  • 通过单击“工具” > “获取工具和功能”,添加工作负荷。Add the workload by clicking Tools > Get Tools and Features.

创建一个 ASP.NET Core Web 应用Create an ASP.NET Core web app

在 Visual Studio 中,通过依次选择“文件”>“新建”>“项目”创建项目。In Visual Studio, create a project by selecting File > New > Project.

在“新建项目”对话框中,选择“Visual C#”>“Web”>“ASP.NET Core Web 应用程序”。In the New Project dialog, select Visual C# > Web > ASP.NET Core Web Application.

将应用程序命名为 myFirstAzureWebApp,然后选择“确定”。Name the application myFirstAzureWebApp, and then select OK.

“新建项目”对话框

可将任何类型的 ASP.NET Core Web 应用部署到 Azure。You can deploy any type of ASP.NET Core web app to Azure. 在本快速入门教程中,请选择“Web 应用程序”模板,并确保身份验证已设置为“无身份验证”且任何其他选项均未选中。For this quickstart, select the Web Application template, and make sure authentication is set to No Authentication and no other option is selected.

选择“确定”。Select OK.

“新建 ASP.NET 项目”对话框

在菜单中,选择“调试>启动但不调试”以在本地运行 Web 应用。From the menu, select Debug > Start without Debugging to run the web app locally.

在本地运行应用

启动发布向导Launch the publish wizard

在“解决方案资源管理器”中右键单击“myFirstAzureWebApp”项目,然后选择“发布”。In the Solution Explorer, right-click the myFirstAzureWebApp project and select Publish.

从解决方案资源管理器发布

发布向导是自动启动的。The publish wizard is automatically launched. 选择“应用服务” > “发布”以打开“创建应用服务”对话框。Select App Service > Publish to open the Create App Service dialog.

从项目概述页发布

登录 AzureSign in to Azure

在“创建应用服务”对话框中单击“添加帐户”,并登录到 Azure 订阅。In the Create App Service dialog, click Add an account, and sign in to your Azure subscription. 如果已登录,请从下拉列表中选择所需的帐户。If you're already signed in, select the account you want from the dropdown.

备注

如果已经登录,请先不要选择“创建”。If you're already signed in, don't select Create yet.

登录 Azure

创建资源组Create a resource group

资源组是在其中部署和管理 Azure 资源(如 Web 应用、数据库和存储帐户)的逻辑容器。A resource group is a logical container into which Azure resources like web apps, databases, and storage accounts are deployed and managed. 例如,可以选择在使用完之后通过一个简单的步骤删除整个资源组。For example, you can choose to delete the entire resource group in one simple step later.

在“资源组”旁边,选择“新建”。Next to Resource Group, select New.

将资源组命名为 myResourceGroup,然后选择“确定”。Name the resource group myResourceGroup and select OK.

创建应用服务计划Create an App Service plan

应用服务计划指定托管应用的 Web 服务器场的位置、大小和功能。An App Service plan specifies the location, size, and features of the web server farm that hosts your app. 可以在托管多个应用时节省资金,方法是将多个 Web 应用配置为共用单个应用服务计划。You can save money when hosting multiple apps by configuring the web apps to share a single App Service plan.

应用服务计划定义:App Service plans define:

  • 区域(例如:北欧、美国东部或东南亚)Region (for example: North Europe, East US, or Southeast Asia)
  • 实例大小(小、中、大)Instance size (small, medium, or large)
  • 规模计数(1 到 20 个实例)Scale count (1 to 20 instances)
  • SKU(免费、共享、基本、标准、高级)SKU (Free, Shared, Basic, Standard, or Premium)

在“托管计划”旁边,选择“新建”。Next to Hosting Plan, select New.

在“配置托管计划”对话框中,使用该屏幕截图下面的表中的设置。In the Configure Hosting Plan dialog, use the settings in the table following the screenshot.

创建应用服务计划

设置Setting建议的值Suggested Value描述Description
应用服务计划App Service Plan myAppServicePlanmyAppServicePlan 应用服务计划的名称。Name of the App Service plan.
位置Location 西欧West Europe 托管 Web 应用的数据中心。The datacenter where the web app is hosted.
大小Size 免费Free 定价层确定托管功能。Pricing tier determines hosting features.

选择“确定”。Select OK.

创建并发布 Web 应用Create and publish the web app

在“应用名称”中,键入唯一的应用名称(有效字符为 a-z0-9-),或接受自动生成的唯一名称。In App Name, type a unique app name (valid characters are a-z, 0-9, and -), or accept the automatically generated unique name. Web 应用的 URL 为 http://<app_name>.azurewebsites.net,其中 <app_name> 是应用名称。The URL of the web app is http://<app_name>.azurewebsites.net, where <app_name> is your app name.

选择“创建”开始创建 Azure 资源。Select Create to start creating the Azure resources.

配置应用名称

向导完成后,它会将 ASP.NET Core Web 应用发布到 Azure,然后在默认浏览器中启动该应用。Once the wizard completes, it publishes the ASP.NET Core web app to Azure, and then launches the app in the default browser.

已在 Azure 中发布的 ASP.NET Web 应用

创建和发布步骤中指定的应用名称用作 http://<app_name>.azurewebsites.net 格式的 URL 前缀。The app name specified in the create and publish step is used as the URL prefix in the format http://<app_name>.azurewebsites.net.

恭喜,ASP.NET Core Web 应用已在 Azure 应用服务中实时运行!Congratulations, your ASP.NET Core web app is running live in Azure App Service.

更新应用并重新部署Update the app and redeploy

在“解决方案资源管理器”中打开“Pages/Index.cshtml”。From the Solution Explorer, open Pages/Index.cshtml.

将两个 <div> 标记替换为以下代码:Replace the two <div> tags with the following code:

HTML
<div class="jumbotron">
    <h1>ASP.NET in Azure!</h1>
    <p class="lead">This is a simple app that we’ve built that demonstrates how to deploy a .NET app to Azure App Service.</p>
</div>

若要重新部署到 Azure,请在“解决方案资源管理器”中右键单击“myFirstAzureWebApp”项目,然后选择“发布”。To redeploy to Azure, right-click the myFirstAzureWebApp project in Solution Explorer and select Publish.

在“发布摘要”页中选择“发布”。In the publish summary page, select Publish. Visual Studio“发布摘要”页Visual Studio publish summary page

发布完成后,Visual Studio 将启动浏览器并转到 Web 应用的 URL。When publishing completes, Visual Studio launches a browser to the URL of the web app.

已在 Azure 中更新的 ASP.NET Web 应用

管理 Azure 应用Manage the Azure app

转到 Azure 门户管理 Web 应用。Go to the Azure portal to manage the web app.

从左侧菜单中选择“应用程序服务”,并选择 Azure 应用的名称。From the left menu, select App Services, and then select the name of your Azure app.

在门户中导航到 Azure 应用

这里我们可以看到 Web 应用的概述页。You see your web app's Overview page. 并可以执行基本的管理任务,例如浏览、停止、启动、重新启动和删除。Here, you can perform basic management tasks like browse, stop, start, restart, and delete.

Azure 门户中的应用服务边栏选项卡

左侧菜单提供了用于配置应用的不同页面。The left menu provides different pages for configuring your app.

清理资源Clean up resources

在前面的步骤中,在资源组中创建了 Azure 资源。In the preceding steps, you created Azure resources in a resource group. 如果将来不再需要这些资源,可以通过删除资源组来删除它们。If you don't expect to need these resources in the future, you can delete them by deleting the resource group.

在 Azure 门户的左侧菜单中,选择“资源组”,然后选择“myResourceGroup”。From the left menu in the Azure portal, select Resource groups and then select myResourceGroup.

在资源组页中,确保列出的资源是要删除的资源。On the resource group page, make sure that the listed resources are the ones you want to delete.

选择“删除”,在文本框中键入 myResourceGroup,然后选择“删除”。Select Delete, type myResourceGroup in the text box, and then select Delete.

后续步骤Next steps

反馈

发送有关以下对象的反馈:

原文地址:https://www.cnblogs.com/zhangguofu/p/10853493.html