Deploying a .Net application on Azure App Service


Deploying a .NET application on Azure App Service involves several steps. Here's a comprehensive guide:


Prerequisites

  1. Azure Account: Ensure you have an active Azure subscription.
  2. .NET Application: Have a working .NET Core or ASP.NET application ready.
  3. Azure CLI: Install the Azure CLI.
  4. Code Editor: Use an IDE like Visual Studio, Visual Studio Code, or any preferred editor.
  5. Git: Install Git if using source control.

Steps to Deploy a .NET Application on Azure App Service

1. Create an Azure App Service

  • Via Azure Portal:

    1. Navigate to the Azure Portal.
    2. Search for "App Services" and click + Create.
    3. Fill in the details:
      • Resource Group: Choose an existing one or create a new one.
      • Name: Provide a unique name for your App Service.
      • Publish: Select "Code" or "Docker" based on your deployment type.
      • Runtime Stack: Choose the appropriate .NET version.
      • Operating System: Select "Windows" or "Linux."
      • Region: Choose a region close to your users.
    4. Review and create the App Service.
  • Via Azure CLI:

    az group create --name MyResourceGroup --location eastus
    az appservice plan create --name MyPlan --resource-group MyResourceGroup --sku F1
    az webapp create --name MyUniqueAppName --resource-group MyResourceGroup --plan MyPlan --runtime "DOTNET|7.0"
    

2. Prepare Your Application for Deployment

  1. Build Your Application:

    • In Visual Studio:
      • Go to Build > Publish.
      • Select "Azure" and follow the wizard to configure your App Service.
    • In CLI:
      dotnet publish -c Release -o ./publish
  2. Configure Application Settings:

    • Add necessary settings in appsettings.json.
    • Optionally, use Azure's Configuration Settings for environment variables.

3. Deploy the Application

Option 1: Deploy via Visual Studio

  1. Right-click on your project and select Publish.
  2. Choose Azure as the target.
  3. Sign in with your Azure account.
  4. Select your App Service and click Publish.

Option 2: Deploy via ZIP Deployment

  1. Compress your publish folder into a .zip file.
  2. Use the Azure CLI to deploy the ZIP:
    az webapp deploy --resource-group MyResourceGroup --name MyUniqueAppName --src-path ./publish.zip

Option 3: Deploy via Git

  1. Push your code to a Git repository (e.g., GitHub, Azure Repos).
  2. Configure Azure App Service for CI/CD:
    • Go to your App Service in the Azure Portal.
    • Under Deployment Center, choose your repository source and branch.

4. Test the Deployment

  1. Navigate to your App Service URL:
    https://<your-app-name>.azurewebsites.net
  2. Verify that your application is running as expected.

5. Monitor and Manage the App

  • Logs: Check logs using the Azure Portal or Azure CLI.
    az webapp log tail --name MyUniqueAppName --resource-group MyResourceGroup
  • Scaling: Use the App Service Plan to scale up (change instance size) or scale out (increase instance count).

6. Optional Enhancements

  • Custom Domain: Configure a custom domain and SSL.
  • App Insights: Enable Application Insights for performance monitoring.
  • Environment Variables: Manage environment-specific settings via Azure Configuration.

This process ensures a seamless deployment of your .NET application to Azure App Service. 

Popular posts from this blog

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Java, Spring Boot Mini Project - Library Management System - Download

ReactJS, Spring Boot JWT Authentication Example

Top 5 Java ORM tools - 2024

Java - Blowfish Encryption and decryption Example

Spring boot video streaming example-HTML5

Google Cloud Storage + Spring Boot - File Upload, Download, and Delete