https://github.com/kontent-ai/sample-app-net
Sample .NET MVC web application using the Kontent.ai Delivery .NET SDK to retrieve content
https://github.com/kontent-ai/sample-app-net
asp-net-mvc aspnet-mvc content-delivery delivery-api dot-net-5 dotnet-5 dotnet-core dotnet5 hacktoberfest headless-cms kentico-kontent kontent-ai-sample net5 netcore netcore31
Last synced: 2 months ago
JSON representation
Sample .NET MVC web application using the Kontent.ai Delivery .NET SDK to retrieve content
- Host: GitHub
- URL: https://github.com/kontent-ai/sample-app-net
- Owner: kontent-ai
- License: mit
- Created: 2016-10-03T13:08:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-12-18T13:45:43.000Z (6 months ago)
- Last Synced: 2025-03-30T06:05:53.408Z (2 months ago)
- Topics: asp-net-mvc, aspnet-mvc, content-delivery, delivery-api, dot-net-5, dotnet-5, dotnet-core, dotnet5, hacktoberfest, headless-cms, kentico-kontent, kontent-ai-sample, net5, netcore, netcore31
- Language: Less
- Homepage: https://docs.kontent.ai/tutorials/develop-apps?tech=dotnet
- Size: 3.4 MB
- Stars: 19
- Watchers: 26
- Forks: 65
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
> [!IMPORTANT]
> This sample app relies on the Dancing Goat project, which is no longer available for creation in Kontent.ai.
>
> If you still wish to use this project, you can import the Dancing Goat project using the [Data Ops](https://github.com/kontent-ai/data-ops) tool by following the instructions provided in our [Dancing Goat repository](https://github.com/kontent-ai-bot/dancing-goat).# Kontent.ai sample ASP.NET Core MVC web application
[](https://github.com/kontent-ai/sample-app-net/actions/workflows/integrate.yml)
[](https://codecov.io/gh/kontent-ai/sample-app-net)
[](https://stackoverflow.com/tags/kontent-ai)
[](https://discord.gg/SKCxwPtevJ)This is a sample ASP.NET Core MVC app that uses the [Kontent.ai Delivery .NET SDK](https://github.com/kontent-ai/delivery-sdk-net) to retrieve content from [Kontent.ai](https://kontent.ai).
## Getting started
To run the app:
1. Clone the app repository
2. Run `npm install && npm run build` in the `DancingGoat` directory to build CSS files for the project ([node.js](https://nodejs.org/) must be installed before running this command)
3. Open the `DancingGoat.sln` solution file and run the app
4. Follow the setup wizard to setup your project or adjust the `\DancingGoat\appsettings.json` file:```jsonc
{
// ...
"DeliveryOptions": {
"ProjectId": "YOUR_PROJECT_ID"
}
// ...
}
```> Follow the [step-by-step tutorial](https://kontent.ai/learn/tutorials/develop-apps/get-started/run-sample-app?tech=dotnet) for even more details.
## Features
### Model generation
With the help of [Kontent.ai model generator](https://github.com/kontent-ai/model-generator-net) you can generate models from your project. This process will create classes that you can work with within your codebase. To run the generation, use the Powershell script [./DancingGoat/Tools/GenerateModels.ps1](https://github.com/kontent-ai/sample-app-net/blob/master/DancingGoat/Tools/GenerateModels.ps1) or Bash script [./DancingGoat/Tools/GenerateModels.sh](https://github.com/kontent-ai/sample-app-net/blob/master/DancingGoat/Tools/GenerateModels.sh).
> Be aware that by default, the scripts downloads the models from the default Dancing Goat project. If you want to download models from your custom project, change the project id inside the script file.
### Edit mode & preview
Content contributors sometimes need to fix errors or typos right when they see them on the website. The sample app allows users to navigate from a piece of content on the site straight to the corresponding content item or element in Kontent.ai.
To see Edit mode in action:
1. In your Kontent.ai project navigate to Project Settings -> API keys to get the Preview API key.
2. Enable Delivery Preview API by adding the key to the `\DancingGoat\appsettings.json` file:```jsonc
{
// ...
"DeliveryOptions": {
"UsePreviewApi": true,
"PreviewApiKey": "YOUR_DELIVERY_PREVIEW_API_KEY"
}
// ...
}
```- **Delivery Preview API**: change the key named `PreviewApiKey` in the `DeliveryOptions` section, and use the Delivery Preview API key as its value. To enable calls over the Delivery Preview API, you also need to change the value to `true` of the key named `UsePreviewApi`.
3. Run the app.
4. Navigate to the **About us** section.
5. Click the **Edit mode** switch in the bottom-left corner.Edit buttons will appear next to each piece of content on the page.
To explore how the functionality is implemented, navigate to the [`TagHelpers`](https://github.com/kontent-ai/sample-app-net/tree/master/DancingGoat/TagHelpers) folder.### Responsive images
The sample app contains a sample implementation of the `img-asset` tag helper from the [Kontent.Ai.AspNetCore](https://www.nuget.org/packages/Kontent.Ai.AspNetCore) NuGet package. Using the `img-asset` tag helper, you can easily create an `img` tag with `srcset` and `sizes` attributes. Read more about [image transformation API](https://kontent.ai/learn/reference/image-transformation).
You can adjust the behaviour in the `appsettings.json` file.```json
"ImageTransformationOptions": {
"ResponsiveWidths": [ 200, 400, 600, 800, 1000, 1200, 1400, 1600, 2000, 4000 ]
},
```### Localized routing
The app demonstrates the usage of language prefixes (e.g. `/en-US/articles`) for localizing URLs for SEO purposes. Each language is identified by its codename, in case of this project, it is `en-US` and `es-ES`.
The used language is obtained from the URL via `/DancingGoat/Infrastructure/RouteRequestCultureProvider` and set as the culture of the app.
## Get involvedCheck out the [contributing](CONTRIBUTING.md) page to see the best places to file issues, start discussions, and begin contributing.