ParkSquare.AspNetCore.Sitemap
1.2.62
Install-Package ParkSquare.AspNetCore.Sitemap -Version 1.2.62
dotnet add package ParkSquare.AspNetCore.Sitemap --version 1.2.62
<PackageReference Include="ParkSquare.AspNetCore.Sitemap" Version="1.2.62" />
paket add ParkSquare.AspNetCore.Sitemap --version 1.2.62
#r "nuget: ParkSquare.AspNetCore.Sitemap, 1.2.62"
// Install ParkSquare.AspNetCore.Sitemap as a Cake Addin
#addin nuget:?package=ParkSquare.AspNetCore.Sitemap&version=1.2.62
// Install ParkSquare.AspNetCore.Sitemap as a Cake Tool
#tool nuget:?package=ParkSquare.AspNetCore.Sitemap&version=1.2.62
Asp.Net Core Sitemap.xml & Robots.txt Generator
Background
This package provides automatic generation of sitemap.xml
and robots.txt
for ASP.NET Core application. Both of these files are considered essential for good
Search Engine Optimization (SEO) and are looked upon favourably by search engines such as Google and Bing.
Save the time and hassle of manually maintaining these files, by using the ASP.NET routing tables to generate a standards-compliant sitemap file. Has configurable options to force HTTPs (all sitemap links will use the https protocol), plus Controller or Action exclusions.
Getting Started
Sitemap is implemented as ASP.NET middleware, and works by looking at all controller routes for valid pages that should be included in the xml output.
By default this will only include GET
verbs. If no explicit attribute is defined on your controller method, it will be assumed to be a GET
.
Any requests to /sitemap.xml
or /robots.txt
will be handled by the Sitemap middleware. The robots file will contain a link directing robots (e.g. Googlebot) to your sitemap.
Once you have installed the Nuget package, add this line to Startup.cs to enable Sitemap:
// Place just above app.UseMvc(..)
app.UseSitemap();
Excluding Controller From Sitemap
To exclude a controller and all actions within it, such as an error or login controller, decorate the controller class with the [SitemapExclude]
attribute:
// All routes in this controller will be ignored
[SitemapExclude]
public class BlahController : Controller
{
[Route("some-route")]
public IActionResult Something()
{
return View();
}
}
Excluding Specific Actions/Routes From Sitemap
To exclude only certain actions, routes, or pages from your sitemap, decorate the action method with the [SitemapExclude]
attribute:
public class BlahController : Controller
{
[SitemapExclude]
[Route("some-route")]
public IActionResult Ignored()
{
return View();
}
[Route("some-other-route")]
public IActionResult NotIgnored()
{
return View();
}
}
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
-
.NETCoreApp 2.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.