【翻譯】使用Visual Studio在Azure上部署Asp.Net Core Web應用

配置運行環境

建立Web應用

In the Visual Studio Start Page, tap New Project.... app

在Visual Studio啓示頁面,點擊New Project… webapp

Alternatively, you can use the menus to create a new project. Tap File > New > Project.... 測試

你也能夠經過菜單來建立一個新的項目。點擊File > New > Project… this

Complete the New Project dialog: spa

完成新項目的建立 3d

  • In the left pane, tap Web

  • 在左邊面板,點擊Web

  • In the center pane, tap ASP.NET Core Web Application (.NET Core)

  • 在中間的面板,點擊選擇Asp.Net Core Web Application(.Net Core)

  • Tap OK

  • 點擊OK

In the New ASP.NET Core Web Application (.NET Core) dialog:

在New Asp.Net Core Web Application(.Net Core)對話框中:

  • Tap Web Application

  • 點擊Web Application

  • Verify Authentication is set to Individual User Accounts

  • Authentication設置成Individual User Accounts

  • Verify Host in the cloud is not checked

  • 不選中Host in the Cloud

  • Tap OK

  • 點擊OK

在本地測試應用

  • Press Ctrl-F5 to run the app locally

  • 按Ctrl+F5在本地運行應用

  • Tap the About and Contact links. Depending on the size of your device, you might need to tap the navigation icon to show the links

  • 點擊About和Contact連接,根據你設備分辨率的大小,你可能須要點擊導航圖標才能看到這些連接。

  • Tap Register and register a new user. You can use a fictitious email address. When you submit, you'll get the following error:
  • 點擊註冊連接註冊一個新的用戶。你能夠輸入虛擬的Email地址,當你點擊提交的時候,你會看到錯誤:

You can fix the problem in two different ways:

你能夠使用如下兩種方式修復問題:

  • Tap Apply Migrations and, once the page updates, refresh the page;

  • 點擊Apply Migrations,等待更新後,刷新頁面

  • Run the following from a command prompt in the project's directory:

  • 在命令終端下,到項目目錄運行如下命令:

dotnet ef database update

The app displays the email used to register the new user and a Log off link.

刷新頁面後,頁面會顯示咱們註冊的新用戶和看到一個Log off的連接。

應用部署到Azure

Right-click on the project in Solution Explorer and select Publish....

在Solution Explorer右鍵項目,點擊Publish

In the Publish dialog, tap Microsoft Azure App Service.

在Publish對話框中,點擊Microsoft Azure App service.

Tap New... to create a new resource group. Creating a new resource group will make it easier to delete all the Azure resources you create in this tutorial.

點擊New建立一個新的資源組。建立新的資源組能夠方便你刪除全部在Azure上建立的範例資源。

Create a new resource group and app service plan:

添加一個新的Resource group和app service plan:

  • Tap New... for the resource group and enter a name for the new resource group

  • 在resource group點擊New,而後爲這個資源組取名

  • Tap New... for the app service plan and select a location near you. You can keep the default generated name

  • 在app service plan點擊New,選擇一個

  • Tap Explore additional Azure services to create a new database

  • 點擊Explore additional Azure services去建立一個新的數據庫

  • Tap the green + icon to create a new SQL Database
  • 點擊綠色的加號圖標建立一個新的Sql數據庫

  • Tap New... on the Configure SQL Database dialog to create a new database server.
  • 在Configure Sql Database對話框中點擊New建立一個新的數據庫

  • Enter an administrator user name and password, and then tap OK. Don't forget the user name and password you create in this step. You can keep the default Server Name
  • 輸入一個管理員名和密碼,點擊OK。不要忘記你設置的用戶名和密碼。ServerName能夠保持默認的。

  • Tap OK on the Configure SQL Database dialog
  • 在Configure SQL Database對話框點擊OK

  • Tap Create on the Create App Service dialog
  • 在Creat App Service對話框點擊Create

  • Tap Next in the Publish dialog
  • 在Publish對話框點擊Next

  • On the Settings stage of the Publish dialog:

  • 點擊Publish對話框的Settings標籤

    • Expand Databases and check Use this connection string at runtime

    • 擴展Databases,選中Use this connection string at runtime

    • Expand Entity Framework Migrations and check Apply this migration on publish

    • 擴展Entity Framework Migrations,選中Apply this migration on publish

  • Tap Publish and wait until Visual Studio finishes publishing your app

  • 點擊Publish,等待Visual Studio完成發佈你的應用。

Visual Studio will publish your app to Azure and launch the cloud app in your browser.

Visual Studio會在發佈到Azure後經過瀏覽器打開你在雲端部署的應用。

在Azure上測試你的應用

  • Test the About and Contact links

  • 測試About和Contact連接

  • Register a new user

  • 註冊一個用戶

更新應用

  • Edit the Views/Home/About.cshtml Razor view file and change its contents. For example:
  • 編輯Views/Home/About.cshtml文件,修改它。參考:
@{
       ViewData["Title"] = "About";
   }
   <h2>@ViewData["Title"].</h2>
   <h3>@ViewData["Message"]</h3>

   <p>My updated about page.</p>
  • Right-click on the project and tap Publish... again
  • 再次右鍵項目點擊Publish

  • After the app is published, verify the changes you made are available on Azure
  • 發佈後,檢查下在Azure端的應用是否改變

清除應用

When you have finished testing the app, go to the Azure portal and delete the app.

當你完成測試後,去Azure後臺刪除這個應用。

  • Select Resource groups, then tap the resource group you created
  • 選擇Resource groups,而後選中你建立的資源組

  • In the Resource group blade, tap Delete
  • 在Resource group選項卡中,點擊Delete

  • Enter the name of the resource group and tap Delete. Your app and all other resources created in this tutorial are now deleted from Azure
  • 輸入資源組名點擊Delete。你的應用和建立的資源在Azure中將會被刪除。

原文連接

https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/publish-to-azure-webapp-using-vs

相關文章
相關標籤/搜索