Skip to content

Sidio.Sitemap.AspNetCore is a lightweight .NET library for generating sitemaps and a sitemap index in ASP .NET Core applications.

License

Notifications You must be signed in to change notification settings

marthijn/Sidio.Sitemap.AspNetCore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sidio.Sitemap.AspNetCore

Sidio.Sitemap.AspNetCore is a lightweight .NET library for generating sitemaps and a sitemap index in ASP .NET Core applications.

In addition to sitemap and sitemap index generation, news, images and video extensions are also supported.

build NuGet Version

Installation

Add the package to your project.

Usage

Sitemap

// di setup
services.AddHttpContextAccessor();
services.AddDefaultSitemapServices<HttpContextBaseUrlProvider>();

// controller
[HttpGet]
public IActionResult Sitemap()
{
    var nodes = new List<SitemapNode> { new ("page.html"), new (Url.Action("Index")) };
    var sitemap = new Sitemap(nodes);
    return new SitemapResult(sitemap);
}

Sitemap and sitemap index

[Route("sitemap.xml")]
public IActionResult SitemapIndex()
{
    var sitemapIndex = new SitemapIndex();
    sitemapIndex.Add(new SitemapIndexNode(Url.Action("Sitemap1")));
    return new SitemapResult(sitemapIndex);
}

[Route("sitemap-1.xml")]
public IActionResult Sitemap1()
{
    // ...
}

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

Used by