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

教程:使用 Azure SQL 数据库将 ASP.NET 应用部署到 AzureTutorial: Deploy an ASP.NET app to Azure with Azure SQL Database

Azure 应用服务提供高度可缩放、自修复的 Web 托管服务。Azure App Service provides a highly scalable, self-patching web hosting service. 本教程演示如何在应用服务中部署数据驱动的 ASP.NET 应用,以及如何将其连接到 Azure SQL 数据库This tutorial shows you how to deploy a data-driven ASP.NET app in App Service and connect it to Azure SQL Database. 完成后,你便拥有了一个在 Azure 中运行并连接到 SQL 数据库的 ASP.NET 应用。When you're finished, you have an ASP.NET app running in Azure and connected to SQL Database.

已在 Azure 应用服务中发布 ASP.NET 应用程序

在本教程中,你将了解如何执行以下操作:In this tutorial, you learn how to:

  • 在 Azure SQL 数据库中创建数据库Create a database in Azure SQL Database
  • 将 ASP.NET 应用连接到 SQL 数据库Connect an ASP.NET app to SQL Database
  • 将应用部署到 AzureDeploy the app to Azure
  • 更新数据模型并重新部署应用Update the data model and redeploy the app
  • 将日志从 Azure 流式传输到终端Stream logs from Azure to your terminal
  • 在 Azure 门户中管理应用Manage the app in the Azure portal

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

先决条件Prerequisites

完成本教程:To complete this tutorial:

安装带有 ASP.NET 和 Web 开发工作负荷的 Visual Studio 2019Install Visual Studio 2019 with the ASP.NET and web development workload.

如果已安装 Visual Studio,请单击“工具” > Get Tools and Features“获取工具和功能”,以便在 Visual Studio 中添加工作负荷。If you've installed Visual Studio already, add the workloads in Visual Studio by clicking Tools > Get Tools and Features.

下载示例Download the sample

  1. 下载示例项目 Download the sample project.

  2. 提取(解压缩)dotnet-sqldb-tutorial-master.zip 文件。Extract (unzip) the dotnet-sqldb-tutorial-master.zip file.

此示例项目包含一个使用 Entity Framework Code First 的基本 ASP.NET MVC 创建-读取-更新-删除 (CRUD) 应用。The sample project contains a basic ASP.NET MVC create-read-update-delete (CRUD) app using Entity Framework Code First.

运行应用Run the app

  1. 在 Visual Studio 中打开 dotnet-sqldb-tutorial-master/DotNetAppSqlDb.sln 文件。Open the dotnet-sqldb-tutorial-master/DotNetAppSqlDb.sln file in Visual Studio.

  2. 键入 Ctrl+F5 在不调试的情况下运行应用。Type Ctrl+F5 to run the app without debugging. 该应用将显示在默认浏览器中。The app is displayed in your default browser.

  3. 选择“新建”链接,创建多个待办事项。Select the Create New link and create a couple to-do items.

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

  4. 测试“编辑”、“详细信息”和“删除”链接。Test the Edit, Details, and Delete links.

该应用使用数据库上下文与数据库进行连接。The app uses a database context to connect with the database. 在此示例中,数据库上下文使用名为 MyDbConnection 的连接字符串。In this sample, the database context uses a connection string named MyDbConnection. 此连接字符串在 Web.config 文件中设置,在 Models/MyDatabaseContext.cs 文件中引用。The connection string is set in the Web.config file and referenced in the Models/MyDatabaseContext.cs file. 在教程后面部分,该连接字符串名称用于将 Azure 应用连接到 Azure SQL 数据库。The connection string name is used later in the tutorial to connect the Azure app to an Azure SQL Database.

将 ASP.NET 应用程序发布到 AzurePublish ASP.NET application to Azure

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

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

  2. 选择 Azure 作为目标,然后单击 下一步Select Azure as your target and click Next.

  3. 确保已选择 Azure 应用服务 (Windows) ,然后单击 下一步Make sure that Azure App Service (Windows) is selected and click Next.

登录并添加应用Sign in and add an app

  1. 发布 对话框中,从帐户管理器下拉菜单中单击 添加帐户In the Publish dialog, click Add an account from the account manager drop down.

  2. 登录到 Azure 订阅。Sign in to your Azure subscription. 如果已登录到 Microsoft 帐户,请确保该帐户包含 Azure 订阅。If you're already signed into a Microsoft account, make sure that account holds your Azure subscription. 如果已登录的 Microsoft 帐户不包含 Azure 订阅,请单击该帐户以添加正确的帐户。If the signed-in Microsoft account doesn't have your Azure subscription, click it to add the correct account.

  3. 应用服务实例 窗格中,单击 +In the App Service instances pane, click +.

    登录 Azure

配置 Web 应用名称Configure the web app name

可保留生成的 Web 应用名称,或将其更改为另一个唯一名称(有效字符是 a-z0-9-)。You can keep the generated web app name, or change it to another unique name (valid characters are a-z, 0-9, and -). Web 应用名称将用作应用默认 URL 的一部分(<app_name>.azurewebsites.net,其中 <app_name> 是 Web 应用的名称)。The web app name is used as part of the default URL for your app (<app_name>.azurewebsites.net, where <app_name> is your web app name). 在 Azure 的所有应用中,Web 应用名称必须是唯一的。The web app name needs to be unique across all apps in Azure.

备注

暂时不要选择 创建Don't select Create yet.

“创建应用服务”对话框

创建资源组Create a resource group

资源组是在其中部署和管理 Azure 资源(例如 Web 应用、数据库和存储帐户)的逻辑容器。A resource group is a logical container into which Azure resources, such as 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.

  1. 在“资源组”旁边单击“新建”。Next to Resource Group, click New.

    在“资源组”旁边单击“新建”。

  2. 将资源组命名为 myResourceGroupName the resource group myResourceGroup.

创建应用服务计划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 you host 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)
  1. 托管计划 旁边,单击 新建Next to Hosting Plan, click New.

  2. 配置应用服务计划 对话框中,使用以下设置配置新的应用服务计划并单击 确定In the Configure App Service Plan dialog, configure the new App Service plan with the following settings and click OK:

    设置Setting 建议的值Suggested value 更多信息For more information
    应用服务计划App Service Plan myAppServicePlanmyAppServicePlan 应用服务计划App Service plans
    位置Location 西欧West Europe Azure 区域Azure regions
    大小Size 免费Free 定价层Pricing tiers

    创建应用服务计划

  3. 单击 创建 并等待创建 Azure 资源。Click Create and wait for the Azure resources to be created.

  4. “发布”对话框显示已配置的资源。The Publish dialog shows the resources you've configured. 单击“完成”。Click Finish.

    已创建的资源

创建服务器和数据库Create a server and database

在创建数据库时之前,需要逻辑 SQL ServerBefore creating a database, you need a logical SQL server. 逻辑 SQL 服务器是一种逻辑构造,其中包含一组作为组管理的数据库。A logical SQL server is a logical construct that contains a group of databases managed as a group.

  1. 发布 对话框中,向下滚动到 服务依赖项 部分。In the Publish dialog, scroll down to the Service Dependencies section. 单击 SQL Server 数据库 旁边的 配置Next to SQL Server Database, click Configure.

    配置 SQL 数据库依赖项

  2. 选择 Azure SQL 数据库,然后单击 下一步Select Azure SQL Database and click Next.

  3. 配置 SQL 数据库 对话框中,单击 +In the Configure Azure SQL Database dialog, click +.

  4. 数据库服务器 旁,单击 新建Next to Database server, click New.

    将生成服务器名称。A server name is generated. 此名称用作服务器 <server_name>.database.windows.net 的默认 URL 的一部分。This name is used as part of the default URL for your server, <server_name>.database.windows.net. 它在 Azure SQL 的所有服务器中必须是唯一的。It must be unique across all servers in Azure SQL. 可以更改服务器名称,但就本教程来说,请保留生成的值。You can change the server name, but for this tutorial, keep the generated value.

  5. 添加管理员用户名和密码。Add an administrator username and password. 有关密码复杂性要求,请参阅密码策略For password complexity requirements, see Password Policy.

    请记住此用户名和密码。Remember this username and password. 以后需要使用此用户名和密码来管理服务器。You need them to manage the server later.

    创建服务器

    重要

    虽然连接字符串中的密码已在 Visual Studio 和应用服务中受到屏蔽,但由于它实际上是保留在某个位置,因此增加了应用的受攻击面。Even though your password in the connection strings is masked (in Visual Studio and also in App Service), the fact that it's maintained somewhere adds to the attack surface of your app. 应用服务可以使用托管服务标识,因此根本不需要将机密保留在代码或应用配置中,这样就消除了上述风险。App Service can use managed service identities to eliminate this risk by removing the need to maintain secrets in your code or app configuration at all. 有关详细信息,请参阅后续步骤For more information, see Next steps.

  6. 单击“确定”。Click OK.

  7. Azure SQL 数据库 对话框中,保留默认生成的 数据库名称In the Azure SQL Database dialog, keep the default generated Database Name. 选择 创建 并等待创建数据库资源。Select Create and wait for the database resources to be created.

    配置数据库

配置数据库连接Configure database connection

  1. 向导完成创建数据库资源后,单击 下一步When the wizard finishes creating the database resources, click Next.

  2. 数据库连接字符串名称 中,键入 MyDbConnectionIn the Database connection string Name, type MyDbConnection. 此名称必须与 Models/MyDatabaseContext.cs 中引用的连接字符串相匹配。This name must match the connection string that is referenced in Models/MyDatabaseContext.cs.

  3. 数据库连接用户名数据库连接密码 中,键入在创建服务器时使用的管理员用户名和密码。In Database connection user name and Database connection password, type the administrator username and password you used in Create a server.

  4. 确保已选择 Azure 应用设置,然后单击 完成Make sure Azure App Settings is selected and click Finish.

    配置数据库连接字符串

  5. 等待配置向导完成,并单击 关闭Wait for configuration wizard to finish and click Close.

部署 ASP.NET 应用Deploy your ASP.NET app

  1. 发布 选项卡中,向上滚动到顶部,然后单击 发布In the Publish tab scroll back up to the top and click Publish. 将 ASP.NET 应用部署到 Azure 后。Once your ASP.NET app is deployed to Azure. 默认浏览器会使用已部署应用的 URL 启动。Your default browser is launched with the URL to the deployed app.

  2. 添加多个待办事项。Add a few to-do items.

    已在 Azure 应用中发布 ASP.NET 应用程序

    祝贺你!Congratulations! 数据驱动 ASP.NET 应用程序当前在 Azure 应用服务中实时运行。Your data-driven ASP.NET application is running live in Azure App Service.

本地访问数据库Access the database locally

使用 Visual Studio 可在 SQL Server 对象资源管理器 中轻松浏览和管理自己在 Azure 的新数据库。Visual Studio lets you explore and manage your new database in Azure easily in the SQL Server Object Explorer. 新数据库已经为您创建的应用服务应用打开了防火墙,但若要从本地计算机访问它(例如从 Visual Studio),必须为本地计算机的公共 IP 地址打开防火墙。The new database already opened its firewall to the App Service app that you created, but to access it from your local computer (such as from Visual Studio), you must open a firewall for your local machine's public IP address. 如果您的 internet 服务提供商更改了您的公共 IP 地址,则需要重新配置防火墙以再次访问 Azure 数据库。If your internet service provider changes your public IP address, you need to reconfigure the firewall to access the Azure database again.

创建数据库连接Create a database connection

  1. 在“视图”菜单中,选择“SQL Server 对象资源管理器”。From the View menu, select SQL Server Object Explorer.

  2. 在“SQL Server 对象资源管理器”顶部,单击“添加 SQL Server”按钮。At the top of SQL Server Object Explorer, click the Add SQL Server button.

配置数据库连接Configure the database connection

  1. 在“连接”对话框中,展开“Azure”节点。In the Connect dialog, expand the Azure node. 此处列出了 Azure 中的所有 SQL 数据库实例。All your SQL Database instances in Azure are listed here.

  2. 选择先前创建的数据库。Select the database that you created earlier. 底部将自动填充前面创建的连接。The connection you created earlier is automatically filled at the bottom.

  3. 键入先前创建的数据库管理员密码,然后单击“连接”。Type the database administrator password you created earlier and click Connect.

    通过 Visual Studio 配置数据库连接

允许来自你的计算机的客户端连接Allow client connection from your computer

此时会打开“新建防火墙规则”对话框。The Create a new firewall rule dialog is opened. 默认情况下,服务器仅允许从 Azure 服务(例如 Azure 应用)连接到其数据库。By default, a server only allows connections to its databases from Azure services, such as your Azure app. 若要从 Azure 外部连接到数据库,请在服务器级别创建防火墙规则。To connect to your database from outside of Azure, create a firewall rule at the server level. 防火墙规则允许本地计算机的公共 IP 地址。The firewall rule allows the public IP address of your local computer.

对话框中已填充了你的计算机的公共 IP 地址。The dialog is already filled with your computer's public IP address.

  1. 请确保选中“添加我的客户端 IP”,然后单击“确定”。Make sure that Add my client IP is selected and click OK.

    创建防火墙规则

    Visual Studio 成功为 SQL 数据库实例创建防火墙设置后,连接将立即显示在“SQL Server 对象资源管理器”中。Once Visual Studio finishes creating the firewall setting for your SQL Database instance, your connection shows up in SQL Server Object Explorer.

    可在此处执行最常见的数据库操作,如运行查询、创建视图和存储过程等。Here, you can perform the most common database operations, such as run queries, create views and stored procedures, and more.

  2. 展开连接 >“数据库” > <你的数据库 > > “表”。Expand your connection > Databases > <your database> > Tables. 右键单击 Todoes 表,然后选择“查看数据”。Right-click on the Todoes table and select View Data.

    探索 SQL 数据库对象

使用 Code First 迁移更新应用Update app with Code First Migrations

可以在 Visual Studio 中使用熟悉的工具,更新 Azure 中的数据库和应用。You can use the familiar tools in Visual Studio to update your database and app in Azure. 此步骤中将使用实体框架中的 Code First 迁移对数据库架构进行更改,并将其发布至 Azure。In this step, you use Code First Migrations in Entity Framework to make a change to your database schema and publish it to Azure.

有关使用 Entity Framework Code First 迁移的详细信息,请参阅使用 MVC 5 的 Entity Framework 6 Code First 入门For more information about using Entity Framework Code First Migrations, see Getting Started with Entity Framework 6 Code First using MVC 5.

更新数据模型Update your data model

在代码编辑器中打开 Models\Todo.csOpen Models\Todo.cs in the code editor. 将以下属性添加到 ToDo 类:Add the following property to the ToDo class:

public bool Done { get; set; }

本地运行 Code First 迁移Run Code First Migrations locally

运行几个命令来更新本地数据库。Run a few commands to make updates to your local database.

  1. 在“工具”菜单中,单击“NuGet 包管理器” > “包管理器控制台”。From the Tools menu, click NuGet Package Manager > Package Manager Console.

  2. 在“程序包管理器控制台”窗口中,启用“Code First 迁移”:In the Package Manager Console window, enable Code First Migrations:

    Enable-Migrations
    
  3. 添加迁移:Add a migration:

    Add-Migration AddProperty
    
  4. 更新本地数据库:Update the local database:

    Update-Database
    
  5. 键入 Ctrl+F5,以便运行该应用。Type Ctrl+F5 to run the app. 测试“编辑”、“详细信息”和“创建”链接。Test the edit, details, and create links.

如果应用程序加载未出错,则 Code First 迁移成功。If the application loads without errors, then Code First Migrations has succeeded. 但页面看上去仍没有变化,这是因为应用程序逻辑尚未使用新属性。However, your page still looks the same because your application logic is not using this new property yet.

使用新属性Use the new property

为了使用 Done 属性,请对代码做一些更改。Make some changes in your code to use the Done property. 简单起见,本教程中将仅更改 IndexCreate 视图,以便在操作过程中查看属性。For simplicity in this tutorial, you're only going to change the Index and Create views to see the property in action.

  1. 打开 Controllers\TodosController.csOpen Controllers\TodosController.cs.

  2. 在第 52 行找到 Create() 方法,并将 Done 添加到 Bind 特性中的属性列表。Find the Create() method on line 52 and add Done to the list of properties in the Bind attribute. 完成后,Create() 方法签名应如下面的代码所示:When you're done, your Create() method signature looks like the following code:

    public ActionResult Create([Bind(Include = "Description,CreatedDate,Done")] Todo todo)
    
  3. 打开 Views\Todos\Create.cshtmlOpen Views\Todos\Create.cshtml.

  4. 在 Razor 代码中,应依次看见使用 model.Description<div class="form-group"> 元素和使用 model.CreatedDate<div class="form-group"> 元素。In the Razor code, you should see a <div class="form-group"> element that uses model.Description, and then another <div class="form-group"> element that uses model.CreatedDate. 紧跟在这两个元素之后,添加另一个使用 model.Done<div class="form-group"> 元素:Immediately following these two elements, add another <div class="form-group"> element that uses model.Done:

    <div class="form-group">
        @Html.LabelFor(model => model.Done, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            <div class="checkbox">
                @Html.EditorFor(model => model.Done)
                @Html.ValidationMessageFor(model => model.Done, "", new { @class = "text-danger" })
            </div>
        </div>
    </div>
    
  5. 打开 Views\Todos\Index.cshtmlOpen Views\Todos\Index.cshtml.

  6. 搜索空的 <th></th> 元素。Search for the empty <th></th> element. 在此元素的正上方,添加下列 Razor 代码:Just above this element, add the following Razor code:

    <th>
        @Html.DisplayNameFor(model => model.Done)
    </th>
    
  7. 查找包含 Html.ActionLink() 帮助器方法的 <td> 元素。Find the <td> element that contains the Html.ActionLink() helper methods. 在此 <td>上面,使用以下 Razor 代码添加另一个 <td> 元素:Above this <td>, add another <td> element with the following Razor code:

    <td>
        @Html.DisplayFor(modelItem => item.Done)
    </td>
    

    这就是要在 IndexCreate 视图中查看更改所需的全部操作。That's all you need to see the changes in the Index and Create views.

  8. 键入 Ctrl+F5,以便运行该应用。Type Ctrl+F5 to run the app.

你现在可以添加一个待办事项,并检查''Done''。You can now add a to-do item and check Done. 然后,它应作为已完成项在主页中显示。Then it should show up in your homepage as a completed item. 请记住,Edit视图不显示Done字段,因为没有更改Edit视图。Remember that the Edit view doesn't show the Done field, because you didn't change the Edit view.

在 Azure 中启用 Code First 迁移Enable Code First Migrations in Azure

代码更改生效(包括数据库迁移)后,将其发布至 Azure 应用,并使用 Code First 迁移更新 SQL 数据库。Now that your code change works, including database migration, you publish it to your Azure app and update your SQL Database with Code First Migrations too.

  1. 与先前的操作相同,右键单击项目,然后选择“发布”。Just like before, right-click your project and select Publish.

  2. 单击 更多操作 > 编辑 以打开发布设置。Click More actions > Edit to open the publish settings.

    打开发布设置

  3. MyDatabaseContext 下拉列表中,为 Azure SQL 数据库选择数据库连接。In the MyDatabaseContext dropdown, select the database connection for your Azure SQL Database.

  4. 选择“执行 Code First 迁移(应用程序启动时运行)”,然后单击“保存”。Select Execute Code First Migrations (runs on application start), then click Save.

    在 Azure 应用中启用 Code First 迁移

发布更改Publish your changes

现已在 Azure 应用中启用了 Code First 迁移,可发布代码更改信息。Now that you enabled Code First Migrations in your Azure app, publish your code changes.

  1. 在发布页中单击“发布”。In the publish page, click Publish.

  2. 再次尝试添加待办事项并选择“完成”,然后,它们将作为已完成项显示在主页中。Try adding to-do items again and select Done, and they should show up in your homepage as a completed item.

    Code First 迁移后的 Azure 应用

所有现有待办事项仍将显示。All your existing to-do items are still displayed. 重新发布 ASP.NET 应用程序时,SQL 数据库中的现有数据不会丢失。When you republish your ASP.NET application, existing data in your SQL Database is not lost. 此外,Code First 迁移仅更改数据架构,而使现有数据保持不变。Also, Code First Migrations only changes the data schema and leaves your existing data intact.

流式传输应用程序日志Stream application logs

可直接通过 Azure 应用将跟踪消息流式传输到 Visual Studio。You can stream tracing messages directly from your Azure app to Visual Studio.

打开 Controllers\TodosController.csOpen Controllers\TodosController.cs.

每个操作都以 Trace.WriteLine() 方法开头。Each action starts with a Trace.WriteLine() method. 添加此代码的目的是演示如何将跟踪消息添加至 Azure 应用。This code is added to show you how to add trace messages to your Azure app.

启用日志流式传输Enable log streaming

  1. 在“视图”菜单中,选择“云资源管理器”。From the View menu, select Cloud Explorer.

  2. Cloud Explorer 中,展开包含应用的 Azure 订阅,并展开 应用服务In Cloud Explorer, expand the Azure subscription that has your app and expand App Service.

  3. 右键单击 Azure 应用,并选择“查看流式处理日志”。Right-click your Azure app and select View Streaming Logs.

    启用日志流式传输

    现在,日志已流式传输到“输出”窗口。The logs are now streamed into the Output window.

    输出窗口中的日志流式传输

    但还无法查看任何跟踪消息。However, you don't see any of the trace messages yet. 因为当首先选择“查看流式处理日志”时,Azure 应用将跟踪级别设置为 Error,此级别只记录错误事件(使用 Trace.TraceError() 方法)。That's because when you first select View Streaming Logs, your Azure app sets the trace level to Error, which only logs error events (with the Trace.TraceError() method).

更改跟踪级别Change trace levels

  1. 若要更改跟踪级别以输出其他跟踪消息,请返回 Cloud ExplorerTo change the trace levels to output other trace messages, go back to Cloud Explorer.

  2. 再次右键单击您的应用,然后选择 在门户中打开Right-click your app again and select Open in Portal.

  3. 在应用的“门户管理”页上,从左侧菜单中选择 应用服务日志In the portal management page for your app, from the left menu, select App Service logs.

  4. 应用程序日志记录(文件系统) 下,选择 详细 级别Under Application Logging (File System), select Verbose in Level. 单击“ 保存”。Click Save.

    将跟踪级别更改为“详细”

    提示

    可试验不同的跟踪级别,以查看每个级别分别显示哪些类型的消息。You can experiment with different trace levels to see what types of messages are displayed for each level. 例如,“信息”级别包括 Trace.TraceInformation()Trace.TraceWarning()Trace.TraceError() 创建的所有日志,但不包括 Trace.WriteLine() 创建的日志。For example, the Information level includes all logs created by Trace.TraceInformation(), Trace.TraceWarning(), and Trace.TraceError(), but not logs created by Trace.WriteLine().

  5. 在浏览器中再次导航到应用( http://<应用名称>.azurewebsites.net),然后尝试在 Azure 中的待办事项列表应用程序周围单击。In your browser navigate to your app again at http://<your app name>.azurewebsites.net, then try clicking around the to-do list application in Azure. 现在,跟踪消息已流式传输到 Visual Studio 中的“输出”窗口。The trace messages are now streamed to the Output window in Visual Studio.

    Application: 2017-04-06T23:30:41  PID[8132] Verbose     GET /Todos/Index
    Application: 2017-04-06T23:30:43  PID[8132] Verbose     GET /Todos/Create
    Application: 2017-04-06T23:30:53  PID[8132] Verbose     POST /Todos/Create
    Application: 2017-04-06T23:30:54  PID[8132] Verbose     GET /Todos/Index
    

停止日志流式传输Stop log streaming

若要停止日志流式传输服务,请单击“输出”窗口中的“停止监视”按钮。To stop the log-streaming service, click the Stop monitoring button in the Output window.

停止日志流式传输

管理 Azure 应用Manage your Azure app

转到 Azure 门户管理 Web 应用。Go to the Azure portal to manage the web app. 搜索并选择“应用服务”。Search for and select App Services.

搜索 Azure 应用服务

选择 Azure 应用名称。Select the name of your Azure app.

在门户中导航到 Azure 应用

你已登录到应用页。You have landed in your app's page.

默认情况下,门户将显示“概览”页。By default, the portal shows the Overview page. 在此页中可以查看应用的运行状况。This page gives you a view of how your app is doing. 在此处还可以执行基本的管理任务,例如浏览、停止、启动、重新启动和删除。Here, you can also perform basic management tasks like browse, stop, start, restart, and delete. 该页左侧的选项卡显示可以打开的不同配置页。The tabs on the left side of the page show the different configuration pages you can open.

Azure 门户中的“应用服务”页

清理资源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.

  1. 在 Azure 门户的 Web 应用的“概述”页中,选择“资源组”下的 myResourceGroup 链接。From your web app's Overview page in the Azure portal, select the myResourceGroup link under Resource group.
  2. 在资源组页上,确保列出的资源是要删除的。On the resource group page, make sure that the listed resources are the ones you want to delete.
  3. 选择“删除”,在文本框中键入“myResourceGroup”,然后选择“删除” 。Select Delete, type myResourceGroup in the text box, and then select Delete.

后续步骤Next steps

在本教程中,你了解了如何执行以下操作:In this tutorial, you learned how to:

  • 在 Azure SQL 数据库中创建数据库Create a database in Azure SQL Database
  • 将 ASP.NET 应用连接到 SQL 数据库Connect an ASP.NET app to SQL Database
  • 将应用部署到 AzureDeploy the app to Azure
  • 更新数据模型并重新部署应用Update the data model and redeploy the app
  • 将日志从 Azure 流式传输到终端Stream logs from Azure to your terminal
  • 在 Azure 门户中管理应用Manage the app in the Azure portal

转到下一教程,了解如何轻松地提高 Azure SQL 数据库连接的安全性。Advance to the next tutorial to learn how to easily improve the security of your connection Azure SQL Database.

更多资源:More resources:

希望优化并节省云支出?Want to optimize and save on your cloud spending?