Azure Cloud, App Service, Key Vault & Application Insights Masterclass
Welcome to Phase 17 (Chapter 47): Azure Cloud Basics โ App Service, Azure SQL, Key Vault, Application Insights & Scaling Masterclass! Microsoft Azure is the cloud platform most tightly integrated with .NET and ASP.NET Core. In this final chapter, we explore core Azure services for .NET developers: Azure App Service (PaaS web hosting), Azure SQL Database, Azure Blob Storage, Key Vault for secret management, Application Insights for telemetry and performance monitoring, Managed Identity, and horizontal scaling.
| Azure Service | Purpose | .NET Integration |
|---|---|---|
| Azure App Service | PaaS hosting for ASP.NET Core web apps and APIs | Deploy via GitHub Actions, Azure CLI, or VS publish |
| Azure SQL Database | Managed SQL Server in the cloud with auto-backups | EF Core with SqlServer provider + connection string |
| Azure Blob Storage | Store unstructured data (files, images, videos) | Azure.Storage.Blobs NuGet package |
| Azure Key Vault | Centralized secret/certificate/key management | Azure.Extensions.AspNetCore.Configuration.Secrets |
| Application Insights | APM: request tracing, exceptions, performance metrics | Microsoft.ApplicationInsights.AspNetCore NuGet |
| Managed Identity | App authenticates to Azure services without credentials | Azure.Identity DefaultAzureCredential |
# Install packages
dotnet add package Azure.Extensions.AspNetCore.Configuration.Secrets
dotnet add package Azure.Identity
# Create Key Vault and add secret via Azure CLI
az keyvault create --name "MyAppKeyVault" --resource-group "MyRG" --location "EastUS"
az keyvault secret set --vault-name "MyAppKeyVault" --name "SqlConnectionString" --value "Server=..."
// Program.cs โ Azure Key Vault with Managed Identity (no credentials needed!)
var keyVaultUri = new Uri(builder.Configuration["KeyVaultUri"]!);
builder.Configuration.AddAzureKeyVault(
keyVaultUri,
new DefaultAzureCredential()); // Uses Managed Identity in Azure, dev credentials locally
// Now access Key Vault secrets like any config value:
var connectionString = builder.Configuration["SqlConnectionString"];
// dotnet add package Microsoft.ApplicationInsights.AspNetCore
// Program.cs โ One-line registration
builder.Services.AddApplicationInsightsTelemetry();
// appsettings.json
{
"ApplicationInsights": {
"InstrumentationKey": "your-key-here"
}
}
// Custom telemetry in your services
public class ProductService
{
private readonly TelemetryClient _telemetry;
public ProductService(TelemetryClient telemetry) { _telemetry = telemetry; }
public async Task CreateProductAsync(Product product)
{
_telemetry.TrackEvent("ProductCreated", new Dictionary<string, string>
{
["ProductId"] = product.Id.ToString(),
["ProductName"] = product.Name,
["Category"] = product.Category
});
}
}
// dotnet add package Azure.Storage.Blobs
public class BlobStorageService
{
private readonly BlobContainerClient _container;
public BlobStorageService(IConfiguration config)
{
var client = new BlobServiceClient(config["AzureStorage:ConnectionString"]);
_container = client.GetBlobContainerClient("product-images");
_container.CreateIfNotExists(PublicAccessType.Blob);
}
public async Task<string> UploadImageAsync(IFormFile file)
{
var blobName = $"{Guid.NewGuid()}{Path.GetExtension(file.FileName)}";
var blobClient = _container.GetBlobClient(blobName);
await using var stream = file.OpenReadStream();
await blobClient.UploadAsync(stream, overwrite: true);
return blobClient.Uri.ToString(); // Public URL of uploaded image
}
}
Q1: What is Managed Identity and why is it better than storing credentials?
Managed Identity gives your Azure App Service an automatically managed identity in Azure Active Directory. Your app can authenticate to Azure services (Key Vault, SQL, Storage) without any stored credentials in config files or environment variables โ eliminating credential rotation overhead and credential leak risks.
Q2: How do Azure App Service Deployment Slots work?
Deployment Slots are live production-like environments (staging, preview) within the same App Service Plan. You deploy to the staging slot, verify the release, then perform a zero-downtime "swap" to production โ with instant rollback by swapping back.
Q3: What is the next step after completing this C# masterclass?
You are now a proficient C# & ASP.NET Core developer! Next steps: build a portfolio project (e-commerce API, social network API), contribute to open-source .NET projects, explore gRPC for microservices, learn Blazor for full-stack C#, and prepare for AZ-204 (Azure Developer) or Microsoft certifications.