1

Is there designed way for the enduser to exclude a page from the sitemap.xml?

"Structure Group hierarchy" (default) is used for sitemap content. The pages we want to exclude has normal names (no the underscore in front).

There is an attribute visible (bool) in the sitemap helper (line 154). How can we influence it with true/false?

1 Answer 1

1

We added parts of url on release base in config e.g.

  <add key="SitemapExcludedUrls" value="search|searchresults|404|500" />

These are then excluded in the sitemap.xml view.

@model SitemapItem
@using System;
@using abc.Site.Helpers
@using System.Text.RegularExpressions;
@{string websiteUrl = ConfigHelper.WebsiteUrl; string excludedUrls = ConfigHelper.SitemapExcludedUrls; }<?xml version="1.0" encoding="UTF-8" ?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
        @SitemapForPagesInFolder(Model.Items, websiteUrl, excludedUrls)
</urlset>
@{
    Layout = null;
    Response.ContentType = "application/xml";

}
@helper SitemapForPagesInFolder(List<SitemapItem> folder, string _websiteUrl,string excludedUrls)
{
foreach (var item in folder)
{
    if (item.Type == "Page" && item.Url.StartsWith("/"))
    {
        if (!Regex.Match(item.Url, "\b"+ excludedUrls + @"\b", RegexOptions.Singleline | RegexOptions.IgnoreCase).Success)
        {
                <url>
                    <loc>@_websiteUrl@(item.Url.EndsWith("/index") ? item.Url.Remove(item.Url.Length - 6) : item.Url)</loc>
                    <lastmod>@item.PublishedDate.Value.ToString("yyyy-MM-ddTHH:mm:ss+00:00")</lastmod>
                </url>
            }
        }
        else
        {
            @SitemapForPagesInFolder(item.Items, _websiteUrl, excludedUrls)
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.