Run sample app
Set up the sample app, connect it to a Kontent.ai sample project, and see firsthand how a front-end application pulls and displays content in a realistic multi-brand setup.
Before you start
Make sure you have the following ready:- A Kontent.ai
account
- .NET SDK 8.0
or newer
- Your favorite code editor, for example, Visual Studio Code
Prepare your sample project
The sample app connects to the multi-brand sample project, a Kontent.ai project that contains content for three fictional brands, each with its own website. This gives you a realistic example of how Kontent.ai handles content for multiple channels from a single project. Using your own copy of the sample project lets you experiment freely with its content and structure.- In Kontent.ai
, click your initials in the bottom left corner.
- Select Projects.
- Click Create new project in the top right corner.
- Select Multi-site sample project and click Continue.
Initialize the app
Clone the sample app repository, open the project folder, and restore the project dependencies.
#Clone the sample app repository
git clone https://github.com/kontent-ai/sample-app-net-mvc.git
#Move into the project folder
cd sample-app-net-mvc
#Restore the project dependencies
dotnet restoreSet up the application configuration
The app's root directory contains theappsettings.json file that defines the settings used to configure the app. Secrets, such as API keys, are stored separately using .NET User Secrets, so they are never committed to version control.
Most settings in the file can be left at their default values. In the following steps, you'll set two required values:
DeliveryOptions:EnvironmentId— connects the app to your sample projectDeliveryOptions:PreviewApiKey— enables the app to display unpublished content
Connect your Kontent.ai project
Each Kontent.ai project has one or more environments. The environment ID uniquely identifies which one the app connects to, and this is what tells the app where to pull content from. To find your environment ID:- In Kontent.ai, open your sample project.
- In
Environment settings > General, click
to copy the Environment ID to your clipboard.

In the
appsettings.json file, set DeliveryOptions:EnvironmentId to your environment ID.Enable content preview
The app supports preview mode, which lets you view unpublished content from Kontent.ai.
Initialize user secrets and store your new Delivery API key, replacing
<preview-api-key>:dotnet user-secrets init
dotnet user-secrets set "DeliveryOptions:PreviewApiKey" "<preview-api-key>"Run the app
Make sure the HTTPS development certificate is trusted. If you haven't done this yet, run:
Start a development server.
The application runs locally at https://localhost:7108 by default.
dotnet dev-certs https \
--trustdotnet runActivate content preview
Append the
, where
If the app crashes on startup or unpublished content doesn't appear, check that the API key placeholder has been replaced with a real value and that the key corresponds to the correct environment.
To turn off preview mode, click Disable in the Preview mode indicator in the bottom-right corner of the page.
secret query parameter to your local URL, such as https://localhost:7108/?secret=mySecretmySecret is the default value of PreviewOptions:Secret. This sets a signed preview cookie, which lets the app use your stored API key to fetch unpublished content.Choose which content to display
The Multi-site sample project represents a fictional healthcare company with three distinct brands: Ficto Imaging, Ficto Healthtech, and Ficto Surgical. Each brand has its own website and content, represented by a collection in Kontent.ai. To choose which brand the app displays, append thecollection query parameter to your local URL, using one of the following codenames: ficto_imaging, ficto_healthtech, or ficto_surgical, for example:
The app remembers your selection and continues serving content from the selected brand as you navigate the site.