Deploying an ASP.NET Core Application to Azure App Service

What is Azure App Service?

Azure App Service is a fully managed platform for building, deploying, and scaling web applications, RESTful APIs, and mobile backends. It supports multiple languages, including .NET, Java, Node.js, and more.

  • Scalability: Automatically scale your applications based on demand.
  • Integrated CI/CD: Easily integrate with GitHub, Azure DevOps, or other CI/CD tools.
  • Secure Hosting: Provides built-in security features like SSL and Azure AD integration.

Why Use Azure App Service for ASP.NET Core?

Azure App Service offers an effortless way to deploy and manage ASP.NET Core applications with high availability and scalability.


Step-by-Step Guide to Deploying to Azure App Service

Follow these steps to deploy your ASP.NET Core application:

1. Set Up Azure Account


// Sign up for Azure if you don’t have an account:
// https://azure.microsoft.com/free/

                

Log in to the Azure Portal at https://portal.azure.com.

2. Publish Your Application Locally


// Use Visual Studio to publish the application:
// 1. Right-click your project in Solution Explorer.
// 2. Select "Publish".
// 3. Choose "Folder" as the target.
// 4. Click "Publish" to generate files locally.

                

The application is now ready for deployment.

3. Create an Azure App Service


// In the Azure Portal:
// 1. Click "Create a Resource".
// 2. Search for "App Service" and select it.
// 3. Click "Create".
// 4. Fill in the required details:
//     - Subscription: Select your subscription.
//     - Resource Group: Create or choose an existing group.
//     - App Name: Give your app a unique name.
//     - Runtime Stack: Select ".NET 7 (LTS)" or your desired version.
//     - Region: Choose a region near your users.
// 5. Click "Review + Create" and then "Create".

                

Wait for the App Service to be provisioned.

4. Deploy via Visual Studio


// In Visual Studio:
// 1. Right-click your project in Solution Explorer.
// 2. Select "Publish".
// 3. Choose "Azure" as the target and click "Next".
// 4. Sign in to your Azure account.
// 5. Select the App Service you created.
// 6. Click "Publish".

                

Visual Studio will deploy the application to Azure App Service.

5. Deploy via Azure CLI


// Install Azure CLI if not already installed:
// https://learn.microsoft.com/en-us/cli/azure/install-azure-cli

// Log in to Azure:
az login

// Deploy your application:
az webapp up --name  --resource-group  --runtime "DOTNETCORE:7.0"

                

This command builds and deploys the application directly from your project folder.

6. Test Your Application


// Open the URL of your App Service:
// https://.azurewebsites.net

                

Your application should now be live and accessible!

7. Enable Continuous Deployment (Optional)


// In the Azure Portal:
// 1. Go to your App Service.
// 2. Under "Deployment Center", configure GitHub or Azure DevOps for automatic deployment.

                

This ensures any new changes are automatically deployed.