.NET Academy

Deploying to the cloud

Hosting options for .NET apps — PaaS, containers and serverless — plus managed databases, configuration and secrets in the cloud.

12 min read

You will learn

  • Compare IaaS, PaaS, containers and serverless
  • Deploy an ASP.NET Core app to Azure App Service or Azure Container Apps
  • Use managed databases, caches and Key Vault
  • Understand cloud costs and managed identities

Where should the app run?

Cloud providers (Azure, AWS, Google Cloud) offer several levels of abstraction. The higher you go, the less you operate yourself:

ModelYou manageProvider managesExamples
IaaS (virtual machines)OS, runtime, patches, app, scalingHardware, networkAzure VMs, AWS EC2
PaaS (app hosting)Your app and its settingsOS, runtime, patching, load balancing, scalingAzure App Service, AWS Elastic Beanstalk
Containers (managed)Your container imageOrchestration, scaling, networkingAzure Container Apps, AWS ECS/Fargate, Google Cloud Run
KubernetesCluster configuration and workloadsControl planeAKS, EKS, GKE
Serverless functionsIndividual functionsEverything else; scale to zeroAzure Functions, AWS Lambda

For a typical ASP.NET Core API, PaaS or managed containers is the sweet spot: little operational work, autoscaling, built-in TLS certificates and deployment slots.

Azure App Service

dotnet publish -c Release -o ./publish
az webapp up --name shop-api --runtime "DOTNETCORE:8.0" --sku B1

Then configure in the portal or CLI:

  • App settings become environment variables — ConnectionStrings__Shop, Payment__TimeoutSeconds.
  • Deployment slots (staging/production) let you deploy to staging, warm it up, then swap with zero downtime.
  • Scale up (bigger plan) or scale out (more instances, autoscale rules).
  • Health check path (/health) so unhealthy instances are replaced.

Azure Container Apps

For containerized apps: push your image to a registry and Container Apps runs it with HTTPS ingress, autoscaling (including scale to zero, and scaling on queue length), revisions for blue/green deployments, and built-in Dapr support for microservices.

Managed services instead of running your own

NeedManaged service (Azure / AWS)
Relational databaseAzure SQL, Azure Database for PostgreSQL / RDS, Aurora
CacheAzure Cache for Redis / ElastiCache
Files and imagesBlob Storage / S3 (+ CDN in front)
Queues and eventsService Bus, Storage Queues / SQS, SNS
SecretsKey Vault / Secrets Manager
MonitoringApplication Insights + Azure Monitor / CloudWatch

Managed services handle backups, patching, replication and failover — work you'd otherwise do yourself.

Secrets and identity in the cloud

Don't put secrets in app settings if you can avoid it. Give the app a managed identity and grant it access:

// The app authenticates as itself — no password in config
builder.Configuration.AddAzureKeyVault(
    new Uri("https://shop-vault.vault.azure.net/"), new DefaultAzureCredential());

DefaultAzureCredential uses your developer login locally and the managed identity in Azure. The same approach works for Azure SQL, Storage and Service Bus.

Infrastructure as code

Clicking resources together in a portal isn't repeatable. Describe them as code — Bicep or ARM (Azure), Terraform (any cloud), Pulumi (in C#!) — version it in git, and apply it from your pipeline. Creating an identical staging environment becomes one command.

Watch the bill

The cloud charges for what's provisioned, not just what's used:

  • Set budgets and alerts from day one.
  • Right-size instances; use autoscaling and scale-to-zero for dev/test.
  • Delete forgotten environments; tag resources by project and owner.
  • Egress (data leaving the cloud) and premium tiers add up — check pricing calculators.

Key takeaways

  • Choose the highest abstraction that fits: PaaS or managed containers for most web APIs, serverless for event-driven work.
  • App settings become environment variables; use deployment slots or revisions for zero-downtime releases.
  • Prefer managed databases, caches, storage and queues over self-hosting.
  • Use managed identities and Key Vault instead of stored secrets, infrastructure as code for repeatability, and budgets for cost control.

Quiz

4 questions · 3 correct to pass
  1. 1.What does PaaS (e.g. Azure App Service) manage for you, compared with a virtual machine?

  2. 2.When is serverless (Azure Functions, AWS Lambda) a good fit?

  3. 3.What's a managed identity?

  4. 4.What's the biggest everyday cost risk in the cloud?

To complete this lesson

  • ○ Pass the quiz (3/4 correct)