Appearance
Are you an LLM? You can read better optimized documentation at /deployment/heroku_deployment.md for this page in Markdown format
Heroku Deployment
Note: This repo is no longer officially maintained as of Jan, 2023. Feel free to use it, fork it and patch it for your own needs.
This document provides a comprehensive guide for deploying, configuring, and maintaining the TheExampleApp on the Heroku platform. It covers both automated and manual deployment workflows, as well as environment-specific configurations required for the application to run correctly.
A hosted version of The ASP.NET example app is available at https://the-example-app-csharp.herokuapp.com/.
For a general overview of deployment strategies, please see the Deployment Overview.
app.json Configuration
The repository includes an app.json file, which serves as the Heroku app manifest. This file automates the application setup, making deployment significantly easier, especially when using the "Deploy to Heroku" button.
json
{
"name": "The example app .NET",
"description": "This is \"The Example App\", a reference for building your own applications using Contentful.",
"repository": "https://github.com/contentful/the-example-app.csharp",
"keywords": [ "aspnet", "core", "contentful", "example" ],
"stack": "heroku-16",
"website": "https://www.contentful.com/",
"logo": "https://the-example-app-nodejs.herokuapp.com/images/logo-node.svg",
"success_url": "/",
"buildpacks": [
{
"url": "https://github.com/jincod/dotnetcore-buildpack"
}
]
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Key Configuration Details
| Key | Description |
|---|---|
name | The display name of the application ("The example app .NET"). |
description | A brief description of the app's purpose as a reference implementation using Contentful. |
repository | The GitHub repository URL for the source code. |
keywords | Tags for categorizing the app: aspnet, core, contentful, example. |
stack | Defines the operating system image the app runs on. This project is configured for heroku-16, which is based on Ubuntu 16.04. Note: heroku-16 is an older stack and is no longer maintained. For new deployments or major updates, migrating to a newer stack like heroku-22 is strongly recommended, which would require updating the .NET Core version and buildpack. |
website | The Contentful website URL. |
logo | URL to the application logo image. |
success_url | The URL path to redirect to after successful deployment (root path /). |
buildpacks | Specifies the buildpack to be used for compiling and running the application. This project uses a community .NET Core buildpack (jincod/dotnetcore-buildpack). This buildpack is responsible for detecting the .NET Core 2.1 project, restoring dependencies via dotnet restore, and publishing the application. |
Environment Configuration
The application requires Contentful API credentials to function correctly. These are loaded through ASP.NET Core's configuration system (see Startup.cs:41). When deploying to Heroku, you must configure these credentials as environment variables or through a configuration file.
Required Configuration
The application uses services.AddContentful(Configuration) to initialize the Contentful client. Ensure your Contentful space credentials are properly configured in your deployment environment.
Staging Environment
For staging deployments, the application supports a StagingHost environment variable (see Startup.cs:44-56). When set in a staging environment, this variable redirects Contentful API requests to the specified staging host, which is useful for testing against staging Contentful environments.
HTTPS Enforcement
In production environments (non-development), the application automatically redirects HTTP requests to HTTPS by inspecting the X-Forwarded-Proto header (see Startup.cs:103-112). Heroku's router sets this header appropriately, so no additional configuration is needed for HTTPS enforcement.
One-click Deployment
The simplest way to deploy the application is by using the "Deploy to Heroku" button found in the README.md. This button automates the entire deployment process using the buildpack method, including app creation, buildpack configuration, and initial setup based on the app.json manifest.