Learn how to deploy ASP.NET Core to Azure App Service step by step. Follow this guide with CLI, Visual Studio & GitHub Actions examples. Start deploying now!
Deploy ASP.NET Core to Azure App Service — A Complete Step-by-Step Guide
If you have ever wondered how to deploy ASP.NET Core to Azure App Service without spending hours wrestling with configuration, you are in the right place. Azure App Service is Microsoft's fully managed platform for hosting web applications, REST APIs, and backend services. It handles infrastructure, patching, and scaling so you can focus on writing code.
In this tutorial, you will learn three proven ways to deploy your ASP.NET Core application to Azure — using the Azure CLI, Visual Studio, and GitHub Actions for CI/CD. By the end, your app will be live on the internet with a real URL.
What Is Azure App Service and Why Use It?
Azure App Service is a Platform-as-a-Service (PaaS) offering that supports .NET, Node.js, Python, Java, and more. For ASP.NET Core developers, it is the fastest path from code to production. Here is why thousands of teams choose it:
- Zero infrastructure management — no VMs to patch, no OS to configure
- Built-in auto-scaling — handle traffic spikes without manual intervention
- Deployment slots — swap staging and production with zero downtime
- Integrated CI/CD — connect to GitHub, Azure DevOps, or Bitbucket
- Custom domains and free SSL — production-ready HTTPS out of the box
- Free tier available — perfect for learning and small projects
Compared to deploying on a raw virtual machine or container, Azure App Service deployment removes all the operational overhead while giving you full control over your application settings, connection strings, and environment variables.
Prerequisites
Before you begin, make sure you have the following installed:
- .NET 8 SDK or later
- Azure CLI (version 2.50+)
- An Azure account (free tier works)
- Visual Studio 2022 or VS Code (optional, for GUI deployment)
Step 1 — Create Your ASP.NET Core Application
If you already have an application, skip to Step 2. Otherwise, let us scaffold a new ASP.NET Core Web API project.
// Open your terminal and run:
// dotnet new webapi -n MyAzureApp
// cd MyAzureApp
// Program.cs — the default minimal API setup
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.MapGet("/", () => "Hello from Azure App Service!")
.WithName("Root")
.WithOpenApi();
app.MapGet("/api/health", () => Results.Ok(new
{
Status = "Healthy",
Timestamp = DateTime.UtcNow,
Environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Unknown"
}))
.WithName("HealthCheck")
.WithOpenApi();
app.Run();
Run dotnet run and navigate to https://localhost:5001 to confirm your app works locally before deploying.
Step 2 — Deploy ASP.NET Core to Azure Using the Azure CLI
The Azure CLI is the fastest way to publish ASP.NET Core to Azure. This method works on Windows, macOS, and Linux, and takes about five minutes.
2.1 — Log In and Set Your Subscription
// Run these commands in your terminal (not C# code):
// az login
// az account set --subscription "Your Subscription Name"
2.2 — Create a Resource Group
A resource group is a logical container for your Azure resources. Choose a region close to your users for the lowest latency.
// az group create --name myapp-rg --location eastus
2.3 — Create an App Service Plan
The App Service Plan defines the compute resources. Use F1 for the free tier or B1 for basic production workloads.
// az appservice plan create \
// --name myapp-plan \
// --resource-group myapp-rg \
// --sku B1 \
// --is-linux
2.4 — Create the Web App and Deploy
Now create the Azure Web App and deploy your code in a single step using az webapp up. This is the simplest path to a working Azure Web App deploy.
// From your project directory:
// az webapp up \
// --name my-aspnetcore-app-2026 \
// --resource-group myapp-rg \
// --plan myapp-plan \
// --runtime "DOTNETCORE:8.0"
The az webapp up command publishes your code, creates the web app if it does not exist, and returns the live URL. Your app is now accessible at https://my-aspnetcore-app-2026.azurewebsites.net.
2.5 — Configure Application Settings
Use application settings instead of hardcoded values for connection strings and API keys:
// az webapp config appsettings set \
// --name my-aspnetcore-app-2026 \
// --resource-group myapp-rg \
// --settings ASPNETCORE_ENVIRONMENT=Production \
// MyApi__BaseUrl=https://api.example.com
// Access these in your C# code:
var apiBaseUrl = builder.Configuration["MyApi:BaseUrl"];
ASP.NET Core automatically reads Azure App Service application settings through its configuration system. The double underscore (__) in the CLI maps to the colon (:) separator in your configuration hierarchy.
Step 3 — Deploy from Visual Studio (GUI Method)
If you prefer a graphical interface, Visual Studio 2022 makes ASP.NET Core Azure deployment a right-click operation.
- Right-click your project in Solution Explorer and select Publish
- Choose Azure as the target, then select Azure App Service (Linux) or Azure App Service (Windows)
- Sign in to your Azure account if prompted
- Select your existing App Service or click Create New to provision one
- Click Publish — Visual Studio builds, packages, and deploys your app
Visual Studio creates a .pubxml publish profile in the Properties/PublishProfiles folder. Add this to your .gitignore if it contains sensitive information.
Step 4 — Set Up CI/CD with GitHub Actions
For production applications, you want automated deployments on every push. GitHub Actions provides free CI/CD for Azure App Service that triggers on every commit to your main branch.
4.1 — Get Your Publish Profile
// Download the publish profile:
// az webapp deployment list-publishing-profiles \
// --name my-aspnetcore-app-2026 \
// --resource-group myapp-rg \
// --xml
Copy the entire XML output and add it as a GitHub repository secret named AZURE_WEBAPP_PUBLISH_PROFILE.
4.2 — Create the GitHub Actions Workflow
Create a file at .github/workflows/deploy.yml in your repository:
// .github/workflows/deploy.yml
// (This is YAML, not C# — shown here for completeness)
//
// name: Deploy to Azure App Service
//
// on:
// push:
// branches: [ main ]
//
// env:
// AZURE_WEBAPP_NAME: my-aspnetcore-app-2026
// DOTNET_VERSION: '8.0.x'
//
// jobs:
// build-and-deploy:
// runs-on: ubuntu-latest
// steps:
// - uses: actions/checkout@v4
//
// - name: Setup .NET
// uses: actions/setup-dotnet@v4
// with:
// dotnet-version: ${{ env.DOTNET_VERSION }}
//
// - name: Restore dependencies
// run: dotnet restore
//
// - name: Build
// run: dotnet build --configuration Release --no-restore
//
// - name: Publish
// run: dotnet publish -c Release -o ./publish
//
// - name: Deploy to Azure Web App
// uses: azure/webapps-deploy@v3
// with:
// app-name: ${{ env.AZURE_WEBAPP_NAME }}
// publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
// package: ./publish
Every push to the main branch now triggers a build, test, and deployment pipeline automatically. This is the industry-standard approach for production ASP.NET Core applications on Azure.
Step 5 — Verify Your Deployment
After deployment, verify everything works with a simple C# integration test or a quick curl command:
// Quick verification using HttpClient
using var client = new HttpClient();
var response = await client.GetAsync(
"https://my-aspnetcore-app-2026.azurewebsites.net/api/health");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Health Check Response: {content}");
// Expected output:
// Health Check Response: {"status":"Healthy","timestamp":"2026-06-30T...","environment":"Production"}
Best Practices for Azure App Service Deployment
Getting your app deployed is just the start. Follow these best practices to run reliably in production:
Use Deployment Slots for Zero-Downtime Releases
// Create a staging slot
// az webapp deployment slot create \
// --name my-aspnetcore-app-2026 \
// --resource-group myapp-rg \
// --slot staging
// Deploy to staging first, then swap to production
// az webapp deployment slot swap \
// --name my-aspnetcore-app-2026 \
// --resource-group myapp-rg \
// --slot staging \
// --target-slot production
Deployment slots let you test changes in a staging environment before swapping into production with zero downtime. If something goes wrong, swap back in seconds.
Enable Health Checks
// In Program.cs, add a proper health check endpoint:
builder.Services.AddHealthChecks()
.AddDbContextCheck<ApplicationDbContext>() // checks database connectivity
.AddUrlGroup(new Uri("https://api.dependency.com/health"), "External API");
var app = builder.Build();
app.MapHealthChecks("/api/health", new HealthCheckOptions
{
ResponseWriter = async (context, report) =>
{
context.Response.ContentType = "application/json";
var result = new
{
Status = report.Status.ToString(),
Checks = report.Entries.Select(e => new
{
Name = e.Key,
Status = e.Value.Status.ToString(),
Duration = e.Value.Duration.TotalMilliseconds
}),
TotalDuration = report.TotalDuration.TotalMilliseconds
};
await context.Response.WriteAsJsonAsync(result);
}
});
Configure the health check path in the Azure Portal under Monitoring > Health check. Azure will automatically restart unhealthy instances.
Configure Logging with Application Insights
// Install the NuGet package:
// dotnet add package Microsoft.ApplicationInsights.AspNetCore
// In Program.cs:
builder.Services.AddApplicationInsightsTelemetry();
// Now you get automatic request tracking, dependency tracking,
// exception logging, and performance metrics in the Azure Portal.
Common Pitfalls and How to Avoid Them
After helping teams deploy ASP.NET Core to Azure App Service across dozens of projects, these are the mistakes I see most often:
- Forgetting to set the environment — Azure defaults to
Production, but verify by settingASPNETCORE_ENVIRONMENTexplicitly in App Settings. Without this, development-only middleware like Swagger UI will not load. - Hardcoding connection strings — Always use Azure App Settings or Azure Key Vault. Never commit secrets to source control.
- Ignoring the App Service logs — Enable diagnostic logging in the Azure Portal. Use
az webapp log tailto stream logs in real time during debugging. - Using the wrong runtime stack — Match the
--runtimeflag to your .NET version exactly. Running a .NET 8 app on a .NET 6 runtime will fail silently or crash on startup. - Skipping the health check endpoint — Without a health check, Azure cannot detect and replace unhealthy instances automatically.
- Not using HTTPS enforcement — Enable
HTTPS Onlyin the Azure Portal or addapp.UseHttpsRedirection()to redirect all HTTP traffic.
Azure App Service Pricing Quick Reference
Understanding the pricing tiers helps you choose the right plan:
- F1 (Free) — 1 GB RAM, 60 minutes/day compute, shared infrastructure. Good for demos and learning.
- B1 (Basic) — 1.75 GB RAM, dedicated compute, custom domains. Starting at roughly $13/month. Suitable for low-traffic production apps.
- S1 (Standard) — Auto-scale, deployment slots, daily backups. Starting at roughly $70/month. Best for production workloads.
- P1v3 (Premium) — Better performance, more memory, VNet integration. Starting at roughly $140/month. For enterprise applications.
Start with the free tier for development and testing, then scale up as your traffic grows. You can change tiers at any time without redeploying your application.
Conclusion — Your ASP.NET Core App Is Live on Azure
You now know three ways to deploy ASP.NET Core to Azure App Service: the Azure CLI for speed, Visual Studio for convenience, and GitHub Actions for automated CI/CD pipelines. Here are the key takeaways:
- Use
az webapp upfor the fastest possible deployment — one command from your project directory - Set up GitHub Actions early — automated deployments pay for themselves within the first week
- Always use deployment slots for production to achieve zero-downtime releases
- Configure health checks and Application Insights from day one — you cannot fix what you cannot see
- Never hardcode secrets — use Azure App Settings and Key Vault instead
Azure App Service handles the heavy lifting of infrastructure management so you can ship features faster. Start with the free tier today, and scale up as your application grows.
Your go-to resource for C#, .NET, and modern software development. Follow along for daily tutorials, tips, and real-world examples.
Comments
Post a Comment