Azure Cloud, App Service, Key Vault & Application Insights Masterclass

โšก C# 12 & .NET 8 ๐ŸŸข Chapter 47 of 35 ๐Ÿ“‚ Phase 17: Deployment & Cloud ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: Azure App Service ยท Azure SQL ยท Azure Blob Storage ยท Azure Key Vault ยท Application Insights ยท Managed Identity ยท DefaultAzureCredential ยท Deployment Slots ยท Scaling

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.

1Azure Services Overview for .NET Developers
Azure ServicePurpose.NET Integration
Azure App ServicePaaS hosting for ASP.NET Core web apps and APIsDeploy via GitHub Actions, Azure CLI, or VS publish
Azure SQL DatabaseManaged SQL Server in the cloud with auto-backupsEF Core with SqlServer provider + connection string
Azure Blob StorageStore unstructured data (files, images, videos)Azure.Storage.Blobs NuGet package
Azure Key VaultCentralized secret/certificate/key managementAzure.Extensions.AspNetCore.Configuration.Secrets
Application InsightsAPM: request tracing, exceptions, performance metricsMicrosoft.ApplicationInsights.AspNetCore NuGet
Managed IdentityApp authenticates to Azure services without credentialsAzure.Identity DefaultAzureCredential
2Azure Key Vault & Managed Identity
Terminal & C# โ€” Azure Key Vault Setup
# 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=..."
C# โ€” Load Secrets from Key Vault in Program.cs โ–ถ Run in Compiler
// 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"];
3Application Insights โ€” Telemetry & Performance Monitoring
C# โ€” Application Insights Setup โ–ถ Run in Compiler
// 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
        });
    }
}
4Azure Blob Storage โ€” File Upload
C# โ€” Azure Blob Storage File Upload โ–ถ Run in Compiler
// 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
    }
}
5Technical FAQs

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.