Appearance
Are you an LLM? You can read better optimized documentation at /deployment/azure_deployment.md for this page in Markdown format
Azure Deployment for TheExampleApp
This document provides a comprehensive guide for deploying, configuring, and maintaining TheExampleApp on Microsoft Azure. The primary hosting target is Azure App Service, which offers native support for the application's ASP.NET Core 2.1 stack.
Deploy to Azure
TheExampleApp is a server-side rendered ASP.NET Core 2.1 application. Its architecture is well-suited for deployment to Azure App Service, a fully managed platform for building, deploying, and scaling web apps.
Key considerations for Azure deployment:
- Runtime: The application is built on
.NET Core 2.1. Azure App Service provides this runtime out-of-the-box. - Configuration: Application secrets and environment-specific settings must be managed through Azure App Service Configuration, not committed to the repository in
appsettings.json. - HTTPS: The application includes logic to enforce HTTPS, which is critical when running behind Azure's load balancers.
For a general overview of deployment strategies, please see the Deployment Overview documentation.
Azure App Service
Azure App Service is the recommended platform for hosting this application. It simplifies infrastructure management and provides robust tools for CI/CD, scaling, and monitoring.
One-Click Azure Deployment
The project repository includes a "Deploy to Azure" button that provides the simplest method for initial deployment:
This one-click deployment will:
- Create the necessary Azure resources (App Service, App Service Plan)
- Deploy the application code to Azure App Service
- Configure the runtime environment for ASP.NET Core 2.1
Post-Deployment Configuration
After deploying to Azure, you need to configure your Contentful credentials:
Navigate to your Azure App Service in the Azure Portal
Go to Configuration > Application settings
Add the following application settings:
ContentfulOptions:SpaceId- Your Contentful space IDContentfulOptions:DeliveryApiKey- Your Contentful Delivery API access tokenContentfulOptions:PreviewApiKey- Your Contentful Preview API access tokenContentfulOptions:UsePreviewApi- Set tofalsefor production
Save the configuration and restart the App Service
Important: Never commit API keys or secrets to appsettings.json in your repository. Always use Azure App Service Configuration for production credentials.
Environment-Specific Configuration
Staging Environment
The application supports a special staging environment configuration for testing against non-production Contentful endpoints:
- Environment Name: Set
ASPNETCORE_ENVIRONMENTtoStagingin Azure App Service Configuration - Staging Host: Configure the
StagingHostenvironment variable to redirect Contentful API requests to an alternative host
When the staging environment is detected, the application will replace "contentful" in API request URLs with the configured StagingHost value. See TheExampleApp/Startup.cs:53-62 and TheExampleApp/Startup.cs:201-213.
Session State Considerations
The application uses server-side session storage with an extended idle timeout of 2 days (configured in TheExampleApp/Startup.cs:90-94). When deploying to Azure App Service:
- Single Instance: Sessions work out-of-the-box with in-memory session storage
- Multiple Instances (Scale-Out): Configure a distributed session state provider (e.g., Azure Cache for Redis) to maintain session consistency across instances
To configure Redis session state, add the Microsoft.Extensions.Caching.StackExchangeRedis package and update session configuration accordingly.
