ASP.NET Core Integration

The Postnomic.Client.AspNetCore NuGet package provides a drop-in blog integration for ASP.NET Core Razor Pages applications. It registers a Razor Pages Area that automatically renders your blog at a c...

Overview

The Postnomic.Client.AspNetCore NuGet package provides a drop-in blog integration for ASP.NET Core Razor Pages applications. It registers a Razor Pages Area that automatically renders your blog at a configurable base path, giving you a fully functional blog with minimal setup.

Installation

Install the package via the .NET CLI:

dotnet add package Postnomic.Client.AspNetCore

Configuration

In your Program.cs, call AddPostnomicBlog() to register all required services:

builder.Services.AddPostnomicBlog(options =>
{
    options.BaseUrl = "https://api.postnomic.com";
    options.ApiKey = "pk_your_blog_key_here";
    options.BlogSlug = "my-dev-blog";
});

Make sure your application is configured to use Razor Pages and map them:

builder.Services.AddRazorPages();

var app = builder.Build();

app.MapRazorPages();
app.Run();

How It Works

The package registers a Razor Pages Area that serves your blog at the /blog base path by default. Behind the scenes, it:

  1. Registers the IPostnomicBlogService HTTP client with your API key and base URL.
  2. Configures a PostnomicApiKeyHandler that automatically injects the X-Api-Key header on every request.
  3. Resolves image URLs through the API's blob proxy for seamless media delivery.
  4. Provides pre-built Razor Pages for the core blog experience.

Available Pages

The integration includes three main pages:

  • Blog Index (/blog) — Displays a paginated listing of published posts with titles, excerpts, cover images, and metadata.
  • Post Detail (/blog/{slug}) — Renders the full post content with author information, tags, categories, and comments.
  • Author Profile (/blog/author/{id}) — Shows the author's bio, headline, social links, and their published posts.

Configuration via appsettings.json

You can also configure the client through your appsettings.json file:

{
  "PostnomicClient": {
    "BaseUrl": "https://api.postnomic.com",
    "ApiKey": "pk_your_blog_key_here",
    "BlogSlug": "my-dev-blog"
  }
}

Then bind it in Program.cs:

builder.Services.AddPostnomicBlog(
    builder.Configuration.GetSection("PostnomicClient")
);

Complete Example

Here is a minimal Program.cs for an ASP.NET Core app with Postnomic integrated:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();
builder.Services.AddPostnomicBlog(options =>
{
    options.BaseUrl = "https://api.postnomic.com";
    options.ApiKey = "pk_your_blog_key_here";
    options.BlogSlug = "my-dev-blog";
});

var app = builder.Build();

app.UseStaticFiles();
app.UseRouting();
app.MapRazorPages();
app.Run();

Navigate to /blog in your browser and your blog content will be rendered automatically.

Next Steps

  • See Customizing Layouts to override the default styling and templates
  • See Configuration Options for all available settings
  • See API Key Authentication to manage your API keys securely

Was this article helpful?

Thank you for your feedback!