Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 1.73 KB

README.md

File metadata and controls

49 lines (35 loc) · 1.73 KB

Sidio.Sitemap.Blazor

Sidio.Sitemap.Blazor is a lightweight .NET library for generating sitemaps in Blazor server applications.

build NuGet Version Coverage Status

Installation

Add the package to your project.

Usage

Sitemap

Register services:

builder.Services
    .AddHttpContextAccessor()
    .AddDefaultSitemapServices<HttpContextBaseUrlProvider>();

Register the middleware. Make sure to choose the correct namespace.

using Sidio.Sitemap.Blazor;

app.UseSitemap();

Add the following attribute to your components (pages) to include them in the sitemap:

@* default *@
@attribute [Sitemap]

@* override route url *@
@attribute [Sitemap("/custom-url")]

@* add change frequency, priority and last modified date *@
@attribute [Sitemap(ChangeFrequency.Daily, 0.5, "2024-01-01")]

The sitemap is accessible at [domain]/sitemap.xml.

FAQ

  • Exception: Unable to resolve service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor' while attempting to activate 'Sidio.Sitemap.AspNetCore.HttpContextBaseUrlProvider'.
    • Solution: call services.AddHttpContextAccessor(); to register the IHttpContextAccessor.

See also