AspNetCore.Docs/aspnetcore/tutorials/publish-to-azure-webapp-usi...

8.6 KiB

title author description ms.author ms.custom ms.date no-loc uid
Publish an ASP.NET Core app to Azure with Visual Studio rick-anderson Learn how to publish an ASP.NET Core app to Azure App Service using Visual Studio. riande devx-track-csharp, mvc 07/10/2019
cookie
Cookie
Blazor
Blazor Server
Blazor WebAssembly
Identity
Let's Encrypt
Razor
SignalR
tutorials/publish-to-azure-webapp-using-vs

Publish an ASP.NET Core app to Azure with Visual Studio

By Rick Anderson ::: moniker range=">= aspnetcore-3.0"

[!INCLUDE Azure App Service Preview Notice]

::: moniker-end

See Publish a Web app to Azure App Service using Visual Studio for Mac if you are working on macOS.

To troubleshoot an App Service deployment issue, see xref:test/troubleshoot-azure-iis.

Set up

Create a web app

In the Visual Studio Start Page, select File > New > Project...

File menu

Complete the New Project dialog:

  • Select ASP.NET Core Web Application.
  • Select Next.

New Project dialog

In the New ASP.NET Core Web Application dialog:

  • Select Web Application.
  • Select Change under Authentication.

New ASP.NET Core Web dialog

The Change Authentication dialog appears.

  • Select Individual User Accounts.
  • Select OK to return to the New ASP.NET Core Web Application, then select Create.

New ASP.NET Core Web authentication dialog

Visual Studio creates the solution.

Run the app

  • Press CTRL+F5 to run the project.
  • Test the Privacy link.

Web application open in Microsoft Edge on localhost

Register a user

  • Select Register and register a new user. You can use a fictitious email address. When you submit, the page displays the following error:

    "A database operation failed while processing the request. Applying existing migrations for Application DB context may resolve this issue."

  • Select Apply Migrations and, once the page updates, refresh the page.

A database operation failed while processing the request. Applying existing migrations for Application DB context may resolve this issue.

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

Web application open in Microsoft Edge. The Register link is replaced by the text Hello user1@example.com!

Deploy the app to Azure

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

Contextual menu open with Publish link highlighted

In the Publish dialog:

  • Select Azure.
  • Select Next.

Publish dialog

In the Publish dialog:

  • Select Azure App Service (Linux).
  • Select Next.

Publish Dialog: select Azure Service

In the Publish dialog select Create a new Azure App Service...

Publish dialog: select Azure Service instance

The Create App Service dialog appears:

  • The App Name, Resource Group, and App Service Plan entry fields are populated. You can keep these names or change them.
  • Select Create.

Create App Service dialog

After creation is completed the dialog is automatically closed and the Publish dialog gets focus again:

  • The new instance that was just created is automatically selected.
  • Select Finish.

Publish dialog: select App Service instance

Next you see the Publish Profile summary page. Visual Studio has detected that this application requires a SQL Server database and it's asking you to configure it. Select Configure.

Publish Profile summary page: configure SQL Server dependency

The Configure dependency dialog appears:

  • Select Azure SQL Database.
  • Select Next.

Configure SQL Server Dependency dialog

In the Configure Azure SQL database dialog select Create a SQL Database

Configure Azure SQL Database dialog

The Create Azure SQL Database appears:

  • The Database name, Resource Group, Database server and App Service Plan entry fields are populated. You can keep these values or change them.
  • Enter the Database administrator username and Database administrator password for the selected Database server (note the account you use must have the necessary permissions to create the new Azure SQL database)
  • Select Create.

New Azure SQL Database dialog

After creation is completed the dialog is automatically closed and the Configure Azure SQL Database dialog gets focus again:

  • The new instance that was just created is automatically selected.
  • Select Next.

Configure Azure SQL Database dialog

In the next step of the Configure Azure SQL Database dialog:

  • Enter the Database connection user name and Database connection password fields. These are the details your application will use to connect to the database at runtime. Best practice is to avoid using the same details as the admin username & password used in the previous step.
  • Select Finish.

Configure Azure SQL Database dialog, connection string details

In the Publish Profile summary page select Settings:

Publish profile summary page: edit settings

On the Settings page of the Publish dialog:

  • Expand Databases and check Use this connection string at runtime.

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

  • Select Save. Visual Studio returns to the Publish dialog.

Publish dialog: Settings panel

Click Publish. Visual Studio publishes your app to Azure. When the deployment completes, the app is opened in a browser.

Publish dialog: Settings panel

Update the app

  • Edit the Pages/Index.cshtml Razor page and change its contents. For example, you can modify the paragraph to say "Hello ASP.NET Core!":

    [!code-htmlIndex]

  • Select Publish from the Publish Profile summary page again.

Publish profile summary page

  • After the app is published, verify the changes you made are available on Azure.

Verify task is complete

Clean up

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

  • Select Resource groups, then select the resource group you created.

Azure Portal: Resource Groups in sidebar menu

  • In the Resource groups page, select Delete.

Azure Portal: Resource Groups page

  • Enter the name of the resource group and select Delete. Your app and all other resources created in this tutorial are now deleted from Azure.

Next steps

Additional resources