How to deploy asp.net core web api to azure app service


In this video we will discuss how to deploy ASP.NET Core Web API along with SQL Server Database to Azure App Service right from with in Visual Studio. The following are the steps.

Create App Service Instance in Azure

In Visual Studio, in the Solution Explorer, right click on the Web API project and click on Publish

Select Azure and click Next

deploy asp.net core web api to azure app service

Select Azure App Service and click Next

deploy asp.net core web api to azure

Click on the + sign. This opens a new window, which allows us to create a new instance of App Service in Azure.

deploy asp.net core api to azure

Provide a name for the App Service Instance. Select your azure Subscription and Resource Group from the respective dropdown list. Click on the New link next to the Hosting Plan dropdownlist. This allows to create a new Hosting Plan.

publish asp.net core api to azure

Provide a name for the hosting plan. Select a Location and the size. Click OK.

visual studio publish api to azure

You should be back on the App Service window, click Create

deploy rest api to azure app service

After a few seconds, App Service instance is created in Azure. By default it is already selected. Click Next.

c# rest api deployment in azure

Azure API Management provides several benefits. We will discuss, what is API Management and the benefits it provide in our upcoming videos. For now, select the checkbox Skip this step and click Finish

azure deploy rest api

Create SQL Database in Azure

Visual Studio is smart enough to detect that our Employee Management API has a dependency on SQL Server database. It is shown under Service Dependencies. Click on the Configure link to create SQL Server Database in Azure.

azure publish rest api

Select Azure SQL Database and click Next

azure deploy web api

Click on the + sign

deploy asp.net web api in azure

Click on the New link next to Database server dropdownlist. Before we can create a SQL Database, we need to create SQL Server Instance.

.net core web api deploy to azure

Provide a Database server name, location, Administrator username, password and click OK.

publish asp.net web api to azure

You are now back on Azure SQL Database. Click Create. This creates SQL Server Instance and the database in azure.

deploy .net core web api to azure app service

Click Next on Configure Azure SQL Database window.

deploying web api with database in azure

Provide a database connection username, password and click Next, then Finish and finally Close.

deploy asp.net web api with database in azure

At this point, you should be back on the Publish page in Visual Studio. We have to tell Visual Studio to execute database migrations when we publish to azure. Click on the Edit link.

web api with sql database deployment in azure

Click on the Settings tab. Expand Entity Framework Migrations. Select Apply this migration on publish checkbox and then Save.

publish web api and sql database to azure

Finally on the Publish page, click the Publish button.

web api deployment in azure

After the deployment is complete. Navigate to the following URLs

  • /api/employees - You will see the list of all employees
  • /swagger/v1/swagger.json - You will see the Emloyee Management OpenAPI specification document.
  • /swagger - You will see the Emloyee Management API documentation.

Azure tutorial for beginners





© 2020 Pragimtech. All Rights Reserved.