Deploy ASP.NET Core to Azure
Deploying an ASP.NET Core application to Azure App Service provides a reliable, scalable platform for hosting web apps. This tutorial walks you through the end‑to‑end process, from prerequisites to CI/CD with GitHub Actions.
Prerequisites
- ASP.NET Core 8.0 SDK
- Visual Studio 2022 (or VS Code)
- Azure account (free tier works)
- Azure CLI installed (
az) - Git installed
1️⃣ Create an Azure App Service
Open Azure Portal → Create a resource → Web App. Use the following settings:
Resource group: MyResourceGroup
Name: my-aspnetcore-app
Publish: Code
Runtime stack: .NET 8
Region: East US
Click Review + create and then Create. The deployment takes a few seconds.
2️⃣ Publish from Visual Studio
- Right‑click the project → Publish.
- Select Azure → Azure App Service (Linux).
- Choose the App Service you just created.
- Click Finish then Publish.
Visual Studio builds and pushes the app. Browse to https://my-aspnetcore-app.azurewebsites.net to verify.
3️⃣ Deploy Using Azure CLI
Open a terminal and run:
az login
az webapp up --name my-aspnetcore-cli --resource-group MyResourceGroup --runtime "DOTNET|8.0"
The command creates the App Service and deploys the current folder contents.
4️⃣ CI/CD with GitHub Actions
Add a workflow file .github/workflows/azure-deploy.yml:
name: Azure Deploy
on:
push:
branches: [ main ]
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore
run: dotnet restore
- name: Build
run: dotnet publish -c Release -o ./publish
- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v2
with:
app-name: my-aspnetcore-app
slot-name: production
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ./publish
Store your publish profile in the repository secret AZURE_WEBAPP_PUBLISH_PROFILE. Every push to main triggers a deployment.
🔧 Troubleshooting
- 500 Internal Server Error: Check the App Service logs in Azure Portal → Log stream.
- Startup timeout: Ensure the
web.configpoints to the correct DLL. - Connection strings: Set them in Azure Portal under Configuration and read via
Configuration["ConnectionStrings:MyDb"].