教學課程:使用 Azure SQL Database 將 ASP.NET 應用程式部署至 AzureTutorial: Deploy an ASP.NET app to Azure with Azure SQL Database

Azure App Service 可提供可高度擴充、自我修復的 Web 主控服務。Azure App Service provides a highly scalable, self-patching web hosting service. 本教學課程示範如何在 App Service 中開發資料驅動的 ASP.NET 應用程式,並將它連線到Azure SQL DatabaseThis tutorial shows you how to deploy a data-driven ASP.NET app in App Service and connect it to Azure SQL Database. 完成時,您的 ASP.NET 應用程式就會在 Azure 中執行,並已連線到 SQL Database。When you're finished, you have an ASP.NET app running in Azure and connected to SQL Database.

已在 Azure App Service 中發佈的 ASP.NET 應用程式

在本教學課程中,您會了解如何:In this tutorial, you learn how to:

  • 在 Azure SQL Database 中建立資料庫Create a database in Azure SQL Database
  • 將 ASP.NET 應用程式連線到 SQL DatabaseConnect 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,請按一下 [工具]**** > [取得工具和功能]**** 在 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

範例專案包含一個使用 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

在 Visual Studio 中開啟 dotnet-sqldb-tutorial-master/DotNetAppSqlDb.sln** 檔案。Open the dotnet-sqldb-tutorial-master/DotNetAppSqlDb.sln file in Visual Studio.

輸入 Ctrl+F5 以執行應用程式而不偵錯。Type Ctrl+F5 to run the app without debugging. 應用程式會在預設瀏覽器中顯示。The app is displayed in your default browser. 選取 [新建]**** 連結,並且建立幾個 [待辦事項]** 項目。Select the Create New link and create a couple to-do items.

[新增 ASP.NET 專案] 對話方塊

測試 [編輯]****、[詳細資料]**** 和 [刪除]**** 連結。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 Database。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

在 [方案總管]**** 中,以滑鼠右鍵按一下 [DotNetAppSqlDb]**** 專案,然後選取 [發佈]****。In the Solution Explorer, right-click your DotNetAppSqlDb project and select Publish.

從方案總管發佈

選取 Azure 作為目標,然後按 [下一步],並確定已選取 [Azure App Service (Windows)],然後再按 [下一步]。Select Azure as your target, click next, and make sure that Azure App Service (Windows) is selected and click next again.

從專案概觀頁面發佈

登入 AzureSign in to Azure

在 [發佈] 對話方塊中,從 [帳戶管理員] 下拉式清單中按一下 [新增帳戶],然後登入您的 Azure 訂用帳戶。In the Publish dialog, click Add an account from the account manager drop down, and then 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.

登入 Azure

注意

如果您已經登入,請勿選取 [建立]****。If you're already signed in, don't select Create yet.

設定 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). Web 應用程式名稱在 Azure 中的所有應用程式之間必須是唯一的。The web app name needs to be unique across all apps in Azure.

建立 App Service 對話方塊

建立資源群組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

App Service 方案會指定用來裝載應用程式的 Web 伺服器陣列位置、大小和功能。An App Service plan specifies the location, size, and features of the web server farm that hosts your app. 在裝載多個應用程式時,您可以將 Web 應用程式設定為共用單一 App Service 方案來節省開支。You can save money when you host multiple apps by configuring the web apps to share a single App Service plan.

App Service 方案可定義: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. 按一下 [App Service 方案]**** 旁邊的 [新增]****。Next to App Service Plan, click New.

  2. 在 [設定 App Service 方案]**** 對話方塊中,使用下列設定來設定新的 App Service 方案︰In the Configure App Service Plan dialog, configure the new App Service plan with the following settings:

    建立 App Service 方案

    設定Setting 建議的值Suggested value 取得詳細資訊For more information
    App Service 方案App Service Plan myAppServicePlanmyAppServicePlan App Service 方案App Service plans
    位置Location 西歐West Europe Azure 區域Azure regions
    大小Size 免費Free 定價層Pricing tiers
  3. [發佈] 對話方塊會顯示您已設定的資源。The Publish dialog shows the resources you've configured. 按一下 [完成] 。Click Finish.

    您已建立的資源

建立伺服器Create a server

建立資料庫之前,您需要邏輯 SQL 伺服器Before 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. 在 [已連線的服務] 底下,按一下 SQL Server 資料庫旁的 [設定]。Click Configure next to SQL Server Database under Connected Services.

    建立 SQL Database

  2. 在 [Azure SQL Database] 對話方塊中,按一下 [資料庫伺服器] 旁的 [新增]。In the Azure SQL Database dialog, click New next to Database Server.

    唯一的伺服器名稱隨即產生。A unique server name is generated. 這個名稱是作為伺服器預設 URL 的一部分,<server_name>.database.windows.netThis 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.

  3. 新增系統管理員使用者名稱和密碼。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 以及 App Service 中),但是它於某處受到維護的事實增加了您應用程式受到攻擊的可能性。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 可以使用受控服務識別來降低此風險,方法是完全免除在您的程式碼或應用程式組態中維護祕密的需求。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.

  4. 按一下 [確定]。Click OK. 尚不要關閉 [設定 SQL Database]**** 對話方塊。Don't close the Configure SQL Database dialog yet.

在 Azure SQL Database 中建立資料庫Create a database in Azure SQL Database

  1. 在 [Azure SQL Database] 對話方塊中︰In the Azure SQL Database dialog:

    • 保留預設產生的資料庫名稱Keep the default generated Database Name.
    • 選取 [建立]。Select Create.

    設定資料庫

  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. 在 [資料庫使用者名稱] 和 [資料庫密碼] 中,分別輸入您在建立伺服器的步驟 3 中使用的管理員使用者名稱和密碼。Enter the Admin username and password you used in Create a server step 3 into the Database username and password respectively.

    設定資料庫連接字串

  4. 選取 [完成]。Select Finish.

在精靈完成建立 Azure 資源的作業後,按一下 [發佈] 將您的 ASP.NET 應用程式部署至 Azure。Once the wizard finishes creating the Azure resources, click Publish to deploy your ASP.NET app to Azure. 預設瀏覽器隨即啟動,瀏覽至部署應用程式的 URL。Your default browser is launched with the URL to the deployed app.

新增幾個待辦事項項目。Add a few to-do items.

已在 Azure 應用程式中發佈的 ASP.NET 應用程式

恭喜!Congratulations! 您的資料導向 ASP.NET 應用程式正在 Azure App Service 中執行。Your data-driven ASP.NET application is running live in Azure App Service.

在本機存取資料庫Access the database locally

Visual Studio 可讓您在 SQL Server 物件總管中,輕鬆地探索和管理新的資料庫。Visual Studio lets you explore and manage your new database easily in the SQL Server Object Explorer.

建立資料庫連接Create a database connection

從 [檢視]**** 功能表選取 [SQL Server 物件總管]****。From the View menu, select SQL Server Object Explorer.

在 [SQL Server 物件總管]**** 上方,按一下 [加入 SQL Server]**** 按鈕。At the top of SQL Server Object Explorer, click the Add SQL Server button.

設定資料庫連接Configure the database connection

在 [連接]**** 對話方塊中,展開 [Azure]**** 節點。In the Connect dialog, expand the Azure node. 此處會列出 Azure 中您所有的 SQL Database 執行個體。All your SQL Database instances in Azure are listed here.

選取您稍早建立的資料庫。Select the database that you created earlier. 系統會自動在下方填入您稍早建立的連線。The connection you created earlier is automatically filled at the bottom.

輸入您稍早建立的資料庫管理員密碼,然後按一下 [連線]****。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.

確定已選取 [加入我的用戶端 IP]****,然後按一下 [確定]****。Make sure that Add my client IP is selected and click OK.

建立防火牆規則

當 Visual Studio 完成建立 SQL Database 執行個體的防火牆設定時,您的連線就會出現在 [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.

展開您的連線 > [資料庫]**** > <your database> > [資料表]****。Expand your connection > Databases > <your database> > Tables. 以滑鼠右鍵按一下 Todoes 資料表並選取 [檢視資料]****。Right-click on the Todoes table and select View Data.

探索 SQL Database 物件

使用 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. 在此步驟中,您會使用 Entity Framework 中的 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 FirstFor 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.

從 [工具]**** 功能表中,按一下 [NuGet 封裝管理員]**** > [封裝管理員主控台]****。From the Tools menu, click NuGet Package Manager > Package Manager Console.

在 [套件管理員主控台] 視窗中,啟用 Code First 移轉:In the Package Manager Console window, enable Code First Migrations:

Enable-Migrations

新增移轉:Add a migration:

Add-Migration AddProperty

更新本機資料庫:Update the local database:

Update-Database

輸入 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.

開啟 Controllers\TodosController.csOpen Controllers\TodosController.cs.

尋找位於行 52 的 Create() 方法,並將 Done 新增至 Bind 屬性 (Attribute) 中的屬性 (Property) 清單。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)

開啟 Views\Todos\Create.cshtmlOpen Views\Todos\Create.cshtml.

在 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>

開啟 Views\Todos\Index.cshtmlOpen Views\Todos\Index.cshtml.

搜尋空白的 <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>

尋找包含 Html.ActionLink() Helper 方法的 <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.

輸入 Ctrl+F5 以執行應用程式。Type Ctrl+F5 to run the app.

您現在可以新增待辦事項項目,並且勾選 [完成]****。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 Database。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.

就像之前一樣,以滑鼠右鍵按一下專案,然後選取 [發佈]****。Just like before, right-click your project and select Publish.

按一下 [設定]**** 來開啟發佈設定。Click Configure to open the publish settings.

開啟發佈設定

在精靈中,按 [下一步]****。In the wizard, click Next.

確定 [MyDatabaseContext (MyDbConnection)]**** 中已填入您的 SQL Database 連接字串。Make sure that the connection string for your SQL Database is populated in MyDatabaseContext (MyDbConnection). 您可能需要從下拉式清單中選取 [myToDoAppDb]**** 資料庫。You may need to select the myToDoAppDb database from the dropdown.

選取 [執行 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.

在發佈頁面中,按一下 [發佈]。In the publish page, click Publish.

嘗試再次新增待辦事項,然後選取 [完成]****,而它們應該會在您的首頁中顯示為已完成的項目。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 Database 中現有的資料不會遺失。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.

開啟伺服器總管Open Server Explorer

從 [檢視]**** 功能表選取 [伺服器總管]****。From the View menu, select Server Explorer. 您可以在 [伺服器總管]**** 中設定 Azure 應用程式的記錄。You can configure logging for your Azure app in Server Explorer.

啟用記錄資料流Enable log streaming

在 [伺服器總管]**** 中,展開 [Azure]**** > [App Service]****。In Server Explorer, expand Azure > App Service.

展開 [myResourceGroup]**** 資源群組,這是您在第一次建立 Azure 應用程式時所建立的資源群組。Expand the myResourceGroup resource group, you created when you first created the Azure app.

以滑鼠右鍵按一下您的 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

若要變更追蹤層級以輸出其他追蹤訊息,請返回 [伺服器總管]****。To change the trace levels to output other trace messages, go back to Server Explorer.

再次以滑鼠右鍵按一下您的 Azure 應用程式,然後選取 [檢視設定]****。Right-click your Azure app again and select View Settings.

在 [應用程式記錄 (檔案系統)]**** 下拉式清單中,選取 [詳細資訊]****。In the Application Logging (File System) dropdown, select Verbose. 按一下 [檔案] 。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().

在瀏覽器中,再次巡覽至您位於 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 入口網站中的 App Service 頁面

清除資源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 Database 中建立資料庫Create a database in Azure SQL Database
  • 將 ASP.NET 應用程式連線到 SQL DatabaseConnect 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 Database 連線的安全性。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?