Publish an ASP.NET Core app to Azure with Visual Studio (original) (raw)

To troubleshoot an App Service deployment issue, see Troubleshoot ASP.NET Core on Azure App Service and IIS.

Set up

Open a free Azure account if you don't have one.

Create a web app

Start Visual Studio 2022 and select Create a new project.

Create a new project from the start window

In the Create a new project dialog, select ASP.NET Core Web App, and then select Next.

Create an ASP.NET Core Web App

In the Configure your new project dialog, name your project, and then select Next.

In the Additional information dialog:

Additional information

Visual Studio creates the solution.

Run the app

Web application open in Microsoft Edge on localhost

Register a user

A database operation failed while processing the request

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 user@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:

Publish dialog

In the Publish dialog:

Publish Dialog: select Azure Service

In the Publish dialog, in the App Service tab, select Create new.

Publish dialog: select Azure Service instance

The Create App Service dialog appears:

Create App Service dialog

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

Publish dialog: select App Service instance

The Publish profile creation progress dialog confirms the publish profile was created. Select Close.

Next you see the Publish Profile summary page. Visual Studio has detected that this application requires a SQL Server database which it has listed in the Service Dependencies pane. Select the ellipsis (...) and then Connect.

Publish Profile summary page: configure SQL Server dependency

The Connect to dependency dialog appears:

Configure SQL Server Dependency dialog

In the Connect to Azure SQL database dialog, select Create new.

Select Create a SQL DB

The Create Azure SQL Database appears:

New Azure SQL Database dialog

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

Select Next

In the next step of the Connect to Azure SQL Database dialog:

Configure Azure SQL Database dialog, connection string details

The Dependency configuration progress dialog confirms the Azure SQL Database is configured. Select Close.

In the Publish Profile summary page select More actions > Edit:

Publish profile summary page: edit settings

On the Settings tab of the Publish dialog:

Publish dialog: Settings panel:Save

Click Publish. Visual Studio publishes your app to Azure. When the deployment completes.

Last step

The app is opened in a browser. Register a new user and log in as the new user to validate the database deployment and run-time connection.

Update the app

@page  
@model IndexModel  
@{  
    ViewData["Title"] = "Home page";  
}  
<div class="text-center">  
    <h1 class="display-4">Welcome</h1>  
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>  
    <p>Hello ASP.NET Core!</p>  
</div>  

Publish profile summary page

Verify task is complete

Clean up

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

Azure Portal: Resource Groups in sidebar menu

Azure Portal: Resource Groups page

Additional resources