How to deploy an ASP.NET Core web application to a cloud platform

Deploying an ASP.NET Core web application to a cloud platform such as Azure involves several steps. We’ll outline the general process for deploying an ASP.NET Core application to Microsoft Azure, one of the popular cloud platforms. The specific steps can vary slightly for other cloud providers like AWS or Google Cloud.

Prerequisites:

There are some prerequisites to deploying our application, such as:

  • An Azure account. If we don't have one, we can sign up for a free trial.

  • An ASP.NET Core web application.

Steps to deploy ASP.NET core app to Azure

We have already created an ASP.NET Core application in the SPA widget below; before deploying, we need to log in to Azure and create a new resource group to create further resources holding the environment for our application to run properly after deployment. Following are the steps to deploy our application to Azure.

  1. The following command is used to create a resource group via Azure CLI. The name of our resource group is answer:

az group create --name answer --location EastUS
  1. The command below is used to create an Azure App Service Plan with a name Asp_project. We can replace the Subscription to Free Trial if the subscription is not purchased or any other subscription. We have used EducativeContent it as our subscription.

az appservice plan create --name Asp_project --resource-group answer --sku S1 --location eastus --subscription EducativeContent
  1. The following command creates a Web App Service to deploy our application, named  AspprojectApp with the dotnet version 7.

az webapp create --name AspprojectApp --resource-group answer --plan Asp_project --runtime "DOTNET|7"
  1. The following command will publish our project so it creates the publish folder that would be needed to run our application on Azure.

dotnet publish --configuration Release
  1. Now, before deploying, we need to zip our project file then we would send this zipped folder to Azure, where we can execute it. So let’s zip our application folder using the command:

cd .. && zip -r project.zip demo_project/*
  1. Now that we have zipped the folder, let’s deploy our application:

az webapp deployment source config-zip --src project.zip --name AspprojectApp --resource-group answer

After executing the command successfully, go to Azure and perform a few configuration steps:

Step no 1: Please go to the resource groups and click on the group "answer" we newly created with command.
1 of 8


Code example

Note: Please enter the credientials of Azure to login to Azure before pressing the “Run” button.

Let’s perform the steps mentioned above in the following SPA.

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

ASP.NET Core web application

Conclusion

We successfully deployed our ASP.NET Core application to Azure by creating a resource group, establishing an App Service Plan, and deploying a Web App Service with .NET Core 7 compatibility. After publishing the project in the Release configuration, we compressed the files into a zip archive and deployed it to Azure using the Azure CLI. This ensures a smooth and scalable hosting solution for our application, providing users with a robust experience on the Azure cloud platform.

Copyright ©2024 Educative, Inc. All rights reserved