在 Azure 中建立 ASP.NET Core Web 應用Create an ASP.NET Core web app in Azure

您如今訪問的是微軟AZURE全球版技術文檔網站,若須要訪問由世紀互聯運營的MICROSOFT AZURE中國區技術文檔網站,請訪問 https://docs.azure.cn.javascript

在 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. 後續步驟

備註html

本文將應用部署到 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.java

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.git

若是尚未 Azure 訂閱,能夠在開始前建立一個免費賬戶If you don't have an Azure subscription, create a free account before you begin.github

先決條件Prerequisites

爲完成此教程,請安裝支持 ASP.NET 和 Web 開發工做負荷的 Visual Studio 2017To complete this tutorial, install Visual Studio 2017 with the ASP.NET and web development workload.web

若是已安裝 Visual Studio 2017:If you've installed Visual Studio 2017 already:sql

  • 經過單擊「幫助」 > 「檢查更新」,在 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

反饋

發送有關如下對象的反饋:

相關文章
相關標籤/搜索