Sidio.Sitemap.Blazor 2.0.2

Prefix Reserved
dotnet add package Sidio.Sitemap.Blazor --version 2.0.2
                    
NuGet\Install-Package Sidio.Sitemap.Blazor -Version 2.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sidio.Sitemap.Blazor" Version="2.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sidio.Sitemap.Blazor" Version="2.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Sidio.Sitemap.Blazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sidio.Sitemap.Blazor --version 2.0.2
                    
#r "nuget: Sidio.Sitemap.Blazor, 2.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sidio.Sitemap.Blazor@2.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sidio.Sitemap.Blazor&version=2.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Sidio.Sitemap.Blazor&version=2.0.2
                    
Install as a Cake Tool

Sidio.Sitemap.Blazor

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

NuGet Version

Versions

Sidio.Sitemap.Core Sidio.Sitemap.AspNetCore Sidio.Sitemap.Blazor
NuGet NuGet Version NuGet Version NuGet Version
Build build build build
Coverage Coverage Status Coverage Status Coverage Status
Requirements .NET Standard, .NET 8+, .NET 8+, AspNetCore .NET 8+, AspNetCore, Blazor server

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.

Providing additional nodes

You can provide additional sitemap nodes by implementing the ISitemapNodeProvider interface. The middleware will detect and use your implementation automatically.

// Implement the ICustomSitemapNodeProvider interface
public class MyCustomSitemapNodeProvider : ICustomSitemapNodeProvider
{
    public IEnumerable<SitemapNode> GetNodes()
    {
        return new List<SitemapNode> { new("/test") };
    }
}

// Register the provider in DI
services.AddCustomSitemapNodeProvider<MyCustomSitemapNodeProvider>();

Security

The HttpContextBaseUrlProvider uses Request.Host which is not considered safe by default. To mitigate this, use one of the following approaches:

  • Implement a custom IBaseUrlProvider that uses a safe way to determine the base URL, for example by using IHttpContextAccessor and validating the host against a whitelist, or by loading a base URL from configuration.
  • Configure Forwarded Headers middleware:
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
    ForwardedHeaders = ForwardedHeaders.XForwardedHost | ForwardedHeaders.XForwardedProto,
    KnownProxies = { IPAddress.Parse("IP_ADDRESS_OF_YOUR_PROXY") }
});

Upgrade to v2.x

In v2.x the reference to Sidio.Sitemap.AspNetCore is replaced by Sidio.Sitemap.Core. This reduces dependencies and makes the library more lightweight.

Breaking changes:

  • The ICustomSitemapNodeProvider now exists in namespace Sidio.Sitemap.Blazor.
  • References or using-statements to Sidio.Sitemap.AspNetCore can be removed.

FAQ

  • Exception: Unable to resolve service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor' while attempting to activate 'Sidio.Sitemap.Blazor.HttpContextBaseUrlProvider'.
    • Solution: call services.AddHttpContextAccessor(); to register the IHttpContextAccessor.
  • Build error (v1.x): The call is ambiguous between the following methods or properties: 'Sidio.Sitemap.Blazor.ApplicationBuilderExtensions.UseSitemap(...)' and 'Sidio.Sitemap.AspNetCore.Middleware.ApplicationBuilderExtensions.UseSitemap(...)'
    • Solution: make sure to use the correct namespace: using Sidio.Sitemap.Blazor;, and not using Sidio.Sitemap.AspNetCore.Middleware;.

See also

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Sidio.Sitemap.Blazor:

Package Downloads
IdentitySuite.Documentations

IdentitySuite Documentations, a ready-to-use OpenId Connect Server based on Openiddict with Microsoft Identity and a comprehensive management shell.

GitHub repositories

This package is not used by any popular GitHub repositories.