Developer forum

Forum » Dynamicweb 10 » Sitemap.xml
Justin Sjouw Dynamicweb Employee
Justin Sjouw
Reply

I have a couple of dw10 solutions, none of which seem to generate a /sitemap.xml.

Any special settings I have to enable to make it appear or is it still in the pipeline?

I was looking for the checkbox to enable the Sitemap based on the URL provider, but that's not available in Settings\Web & HTTP\Customized URL's

Br,

Justin


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Justin,

This feature is coming with 10.1.

- Jeppe

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Justin,

Until the new sitemap functionality is released you can generate a sitemap by setting up a page...

  1. Create a new page
  2. Set "Exact URL for this page" to "sitemap.xml"
  3. Set content type to "text/xml"
  4. Hide the page from regular navigations by setting "Publication" to "Hidden in menu" and disable "Show in breadcrumb", "Show in searches", "Show in sitemap".
  5. Set the page layout template to a custom template which renders the sitemap xml (see example below).

Note: If you later want to use the standard sitemap functionality then you need to delete or unpublish this custom sitemap page.

@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>
@{
    Uri baseUrl = new Uri(Dynamicweb.Context.Current.Request.Url.GetLeftPart(UriPartial.Authority));

    var settings = new Dynamicweb.Frontend.Navigation.NavigationSettings()
    {
        StartLevel = 1,
        StopLevel = 10,
        RootAreaId = Model.Area.ID,
        ExpandMode = Dynamicweb.Frontend.Navigation.ExpandMode.All,
        IncludeFoldersAndHidden = true
    };

    var navigation = GetNavigation(settings);

    var stack = new Stack<Dynamicweb.Frontend.Navigation.NavigationTreeNodeViewModel>(navigation.Nodes.Reverse());
}
<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    @{
        while (stack.Count > 0)
        {
            var node = stack.Pop();

            if (node.ShowInSitemap)
            {
                var url = new Uri(baseUrl, node.Link);

                <url>
                    <loc>@url.AbsoluteUri</loc>
                </url>
            }

            foreach (var child in node.Nodes.Reverse())
            {
                stack.Push(child);
            }
        }
    }
</urlset>
 
Justin Sjouw Dynamicweb Employee
Justin Sjouw
Reply

Hi guys, thanks!

Would be good to have a temporary fix, I tried to apply this but have 2 issues:

1: even when i set the exact url, the url stays on default.aspx?pageid. Do I need an additional setting (ofcourse I recycled and rebooted, even slept on it, but is stays fixed on the wrong url)

When I preview the page in the default.aspx link I do get some xml, but also an error, both are below. I'll dive in to in later this week myself, but maybe I'm missing something obvious?


<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
                <url>
                    <loc>https://localhost:5516/Default.aspx?ID=149</loc>
                </url>
                <url>
                    <loc>https://localhost:5516/Default.aspx?ID=149&GroupID=GROUP179</loc>
                </url>
                <url>
                    <loc>https://localhost:5516/Default.aspx?ID=149&GroupID=GROUP180</loc>
                </url>
                <url>
                    <loc>https://localhost:5516/Default.aspx?ID=149&GroupID=GROUP160</loc>
                </url>
                <url>
                    <loc>https://localhost:5516/Default.aspx?ID=149&GroupID=GROUP144</loc>
                </url>
                <url>
                    <loc>https://localhost:5516/Default.aspx?ID=149&GroupID=GROUP122</loc>
                </url>
                <url>
                    <loc>https://localhost:5516/Default.aspx?ID=149&GroupID=GROUP96</loc>
                </url>
                <url>
                    <loc>https://localhost:5516/Default.aspx?ID=149&GroupID=GROUP2</loc>
                </url>
                <url>
                    <loc>https://localhost:5516/Default.aspx?ID=150</loc>
                </url>
</urlset>

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

I will look at the URL issue.

The XML error I think is because the <loc> at line 7 contains & which needs to be encoded when used in XML.

BR Nicolai

 
Justin Sjouw Dynamicweb Employee
Justin Sjouw
Reply

I see the ootb option now works on 10.0.31. Thanks very much and enjoy the weekend!

 

You must be logged in to post in the forum