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

Azure 应用服务提供高度可缩放、自修复的 Web 托管服务。Azure App Service provides a highly scalable, self-patching web hosting service.

本快速入门演示如何将第一个 ASP.NET Web 应用部署到 Azure 应用服务中。This quickstart shows how to deploy your first ASP.NET web app to Azure App Service. 完成后,你将拥有一个应用服务计划。When you're finished, you'll have an App Service plan. 还将获得一个应用服务应用,其中包含已部署的 Web 应用程序。You'll also have an App Service app with a deployed web application.

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


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

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

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

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

按照以下步骤创建 ASP.NET Web 应用:Create an ASP.NET web app by following these steps:

  1. 打开 Visual Studio,然后选择“创建新项目”。Open Visual Studio and then select Create a new project.

  2. 在“创建新项目”中,找到并选择“ASP.NET Web 应用程序(.NET Framework)”,然后选择“下一步”。In Create a new project, find and choose ASP.NET Web Application (.NET Framework), then select Next.

  3. 在“配置新项目”中,将应用程序命名为“myFirstAzureWebApp”,然后选择“创建”。In Configure your new project, name the application myFirstAzureWebApp, and then select Create.

    配置 Web 应用项目

  4. 可将任何类型的 ASP.NET Web 应用部署到 Azure。You can deploy any type of ASP.NET web app to Azure. 对于本快速入门,请选择“MVC”模板。For this quickstart, choose the MVC template.

  5. 确保身份验证设置为“不进行身份验证”。Make sure authentication is set to No Authentication. 选择“创建”。Select Create.

    创建 ASP.NET Web 应用程序

  6. 在 Visual Studio 菜单中,选择“调试” > “开始执行(不调试)”以在本地运行 Web 应用。 From the Visual Studio menu, select Debug > Start Without Debugging to run the web app locally.


发布 Web 应用 Publish your web app

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

  2. 选择“应用服务”,并选择“创建配置文件”。Choose App Service and select Create profile.


  3. 在“创建新的应用服务”中,你的选项取决于你是否已登录 Azure 以及是否有一个链接到 Azure 帐户的 Visual Studio 帐户。In App Service Create new, your options depend on whether you're signed in to Azure already and whether you have a Visual Studio account linked to an Azure account. 选择“添加帐户”或“登录”以登录 Azure 订阅。Select either Add an account or Sign in to sign in to your Azure subscription. 如果你已经登录,请选择所需的帐户。If you're already signed in, select the account you want.


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

    登录 Azure

    资源组是在其中部署和管理 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.

  4. 对于“资源组”,选择“新建”。For Resource group, select New.

  5. 在“新资源组名称”中,输入“myResourceGroup”并选择“确定”。In New resource group name, enter myResourceGroup and select OK.

    应用服务计划指定托管应用的 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:

    • 区域(例如:中国东部、中国东部 2、中国北部、中国北部 2)Region (for example: China East, China East 2, China North, China North 2)
    • 实例大小(小、中、大)Instance size (small, medium, or large)
    • 规模计数(1 到 20 个实例)Scale count (1 to 20 instances)
    • SKU(免费、共享、基本、标准、高级)SKU (Free, Shared, Basic, Standard, or Premium)
  6. 对于托管计划,请选择“新建”。For to Hosting Plan, select New.

  7. 在“配置托管计划”对话框中,输入下表中的值,然后选择“确定”。In the Configure Hosting Plan dialog, enter the values from the following table, and then select OK.

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


  8. 名称中,输入仅包含有效字符 a-zA-Z0-9- 的唯一应用名称。In Name, enter a unique app name that includes only the valid characters are a-z, A-Z, 0-9, and -. 可以接受自动生成的唯一名称。You can accept the automatically generated unique name. Web 应用的 URL 为 http://<app_name>.chinacloudsites.cn,其中 <app_name> 是应用名称。The URL of the web app is http://<app_name>.chinacloudsites.cn, where <app_name> is your app name.

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


    向导完成后,便为你创建了 Azure 资源,你就可以进行发布了。Once the wizard completes, the Azure resources are created for you and you are ready to publish.

  10. 在“发布”页中,单击“发布”。In the Publish page, click Publish. Visual Studio 将生成、打包应用并将其发布到 Azure,然后在默认浏览器中启动该应用。Visual Studio builds, packages, and publishes the app to Azure, and then launches the app in the default browser.

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

在“创建新的应用服务”页中指定的应用名称将用作 http://<app-name>.chinacloudsites.cn 格式的 URL 前缀。The app name specified in the App Service Create new page is used as the URL prefix in the format http://<app-name>.chinacloudsites.cn.

祝贺你!Congratulations! 你的 ASP.NET Web 应用已在 Azure 应用服务中实时运行!Your ASP.NET web app is running live in Azure App Service.

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

  1. 解决方案资源管理器中你的项目下,打开“视图” > “主页” > “Index.cshtml”。In Solution Explorer, under your project, open Views > Home > Index.cshtml.

  2. 在顶部附近找到 <div class="jumbotron"> HTML 标记,将整个元素替换为以下代码:Find the <div class="jumbotron"> HTML tag near the top, and replace the entire element with the following code:

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

    发布完成后,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

  1. 若要管理 Web 应用,请转到 Azure 门户,搜索并选择“应用服务”。To manage the web app, go to the Azure portal, and search for and select App Services.


  2. 在“应用服务”页上,选择 Web 应用的名称。On the App Services page, select the name of your web app.

    在门户中导航到 Azure 应用

    随后会显示 Web 应用的概述页。You see your web app's Overview page. 在这里,可以进行基本的管理,如浏览、停止、启动、重启和删除。Here, you can do basic management 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