An open API service indexing awesome lists of open source software.

https://github.com/kontent-ai/aspnetcore-extensions

ASP.NET Core extensions for Kontent.ai apps.
https://github.com/kontent-ai/aspnetcore-extensions

asp-net kontent-ai kontent-ai-tool middleware middlewares tag-helper tag-helpers

Last synced: about 1 month ago
JSON representation

ASP.NET Core extensions for Kontent.ai apps.

Awesome Lists containing this project

README

        

# ASP.NET Core extensions for Kontent.ai apps

[![NuGet](https://img.shields.io/nuget/vpre/Kontent.Ai.AspNetCore.svg)](https://www.nuget.org/packages/Kontent.Ai.AspNetCore/)
[![Downloads](https://img.shields.io/nuget/dt/Kontent.Ai.AspNetCore.svg)](https://www.nuget.org/packages/Kontent.Ai.AspNetCore/)
[![Build & Test](https://github.com/kontent-ai/aspnetcore/actions/workflows/integrate.yml/badge.svg)](https://github.com/aspnetcore/actions/workflows/integrate.yml)
[![codecov](https://codecov.io/gh/kontent-ai/aspnetcore/branch/master/graph/badge.svg?token=U4Y9PQDW6Q)](https://codecov.io/gh/kontent-ai/aspnetcore)
[![Stack Overflow](https://img.shields.io/badge/Stack%20Overflow-ASK%20NOW-FE7A16.svg?logo=stackoverflow&logoColor=white)](https://stackoverflow.com/tags/kontent-ai)
[![Discord](https://img.shields.io/discord/821885171984891914?color=%237289DA&label=Kontent.ai%20Discord&logo=discord)](https://discord.gg/SKCxwPtevJ)

## Tag Helpers

### `img-asset` tag helper

Useful for rendering responsive images. Supports Assets and Inline images in rich-text elements.

`appsettings.json`:

```json
...
"ImageTransformationOptions": {
"ResponsiveWidths": [ 200, 300, 400, 600, 800, 1000, 1200, 1400, 1600, 2000 ]
}
...
```

`\_ViewImports.cshtml`:

```razor
@addTagHelper *, Kontent.Ai.AspNetCore
```

`Startup.cs`:

```csharp
public void ConfigureServices(IServiceCollection services)
{
// Adds services required for using options.
services.AddOptions();

// Register the ImageTransformationOptions required by Kontent.ai tag helpers
services.Configure(Configuration.GetSection(nameof(ImageTransformationOptions)));
}
```

`View.cshtml`:

```razor


```

#### Output

```html
Coffee Brewing Techniques
```

## Webhooks

Package provides a model for webhook deserialization: `WebhookNotification`. Legacy webhooks are supported via classes `DeliveryWebhookModel` and `ManagementWebhookModel`, to be used with legacy (preview) delivery API and management API triggers respectively. See [Webhooks reference](https://kontent.ai/learn/reference/webhooks-reference/) in Kontent.ai documentation.

## Middlewares

### Webhook signature verification middleware

This middleware verifies the `X-Kontent-ai-Signature` (and the legacy `X-KC-Signature`) header. Returns 401 response if the signature is invalid.

`appsettings.json`:

```json
...
"WebhookOptions": {
"Secret": ""
},
...
```

`Startup.cs`:

```csharp
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Register the validation middleware for any number of controllers that serve for processing webhooks
app.UseWebhookSignatureValidator(context => context.Request.Path.StartsWithSegments("/webhooks/webhooks", StringComparison.OrdinalIgnoreCase), Configuration.GetSection(nameof(WebhookOptions)));
}
```