Thank you Ella!
I made it in a similar way.
1. I created a view "Article.Sitemap" to enumerate all articles in my site. This is source code of a view:
Code:
@{
string baseUri = String.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority);
if (ViewBag.Articles != null) {
foreach (var item in ViewBag.Articles) {
<url>
<loc>@baseUri@Url.FrontUrl().PageUrl("Article/Detail", new { UserKey = item.UserKey })</loc>
<changefreq>weekly</changefreq>
<priority>0.80</priority>
</url>
}
}
}
2. I added DataRule "Articles" to view "Article.Sitemap". This DataRule just contains unfiltered list of articles in my site. This list could be sorted. I also recommend to limit maximum number of items in this list to prevent resulting sitemap.xml file size increase over limit. Some search engines enforce limits to sitemap.xml.
3. I created layout "SiteMap" with following contents:
Code:
@{
string baseUri = String.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority);
Response.ContentType = "application/xml";
}
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>@baseUri</loc>
<changefreq>weekly</changefreq>
<priority>1.00</priority>
</url>
<url>
<loc>@baseUri@Url.FrontUrl().PageUrl("Tip")</loc>
<changefreq>weekly</changefreq>
<priority>0.80</priority>
</url>
<url>
<loc>@baseUri@Url.FrontUrl().PageUrl("About")</loc>
<changefreq>monthly</changefreq>
<priority>0.80</priority>
</url>
@Html.FrontHtml().RenderView("Article.Sitemap",ViewData)
</urlset>
It's important to change MIME type by code
Response.ContentType = "application/xml"; because resulting file should be treated as XML, but not as HTML. Also using baseUri variable is useful for adopting for other sites.
Line
@Html.FrontHtml().RenderView("Article.Sitemap",ViewData) is a place for adding view "Article.Sitemap" created at step 1. It's easy to create this line by using Kooboo's Code helper in layout editor.
4. I created page "sitemap.xml" based on layout "SiteMap". I do not recommend to show this page in menu :).
Result is valid xml, that I cheched by various online validators like
http://sitemapxml.net/sitemap-validator.php.
P.S. Thank you for
http://kooboo-cms.ru! Congratulations on International Women's Day! :)
Petr Alexeev
MVP