Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Umbraco Xml Sitemap using Razor
<system.webServer>
<rewrite>
<rules>
<rule name="Xml Sitemap">
<match url="sitemap.xml"/>
<action type="Rewrite" url="xmlsitemap"/>
</rule>
</rules>
</rewrite>
</system.webServer>
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = null;
var root = Umbraco.TypedContentSingleAtXPath("//homePage");
umbraco.library.ChangeContentType("text/xml");
}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@renderUrl(root)
</urlset>
@helper renderUrl(IPublishedContent node)
{
var changeFreq = (node.HasValue("changeFrequency")) ? node.GetPropertyValue<string>("changeFrequency").ToLower() : "monthly";
var priority = node.GetPropertyValue<double>("crawlPriority");
<url>
<loc>@node.UrlAbsolute()</loc>
<lastmod>@node.UpdateDate.ToString("yyyy-MM-dd")</lastmod>
<changefreq>@changeFreq</changefreq>
<priority>@((priority == 0) ? 0.5 : priority)</priority>
</url>
if (node.Children.Any())
{
foreach (var child in node.Children)
{
@renderUrl(child)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment