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.
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.
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.
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
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
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"
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
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/*
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:
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": "*" }
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.