Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jan Brinker 77 posts 103 karma points
    May 23, 2013 @ 13:10
    Jan Brinker
    1

    Fix for crash of Razor-variant v1.0.2 in Umbraco 6.0.5

    Ahoy,

    I just encountered a bug in the Razor variant of the plugin, which made it crash when running.

    I isolated the problem and fixed it. The new code is as follows:

    @ListChildNodes(Model.AncestorOrSelf(1))

    @helper ListChildNodes(dynamic startNode)
    {
    Response.ContentType = "text/xml";
    const int maxLevelForSiteMap = 100;


    foreach (var node in startNode.Children
    .Where("HasAccess")
    .Where("!IsProtected")
    .Where("umbracoNaviHide == false"))
    {
    if(node.template > 0) {
    <url>
    <loc>@GetUrlWithDomainPrefix(node.Url)</loc>
    <lastmod>@(string.Format("{0:s}+00:00", node.UpdateDate))</lastmod>
    @if (node.SearchEngineSitemapChangeFreq.ToString() != "")
    {
    <changefreq>@node.SearchEngineSitemapChangeFreq</changefreq>
    }
    @if (node.SearchEngineSitemapPriority.ToString() != "")
    {
    <priority>@node.SearchEngineSitemapPriority</priority>
    }
    </url>
    }

    if (node.Level <= maxLevelForSiteMap && node.ChildrenAsList.Count() > 0)
    {
    @ListChildNodes(node)
    }
    }
    }

    @functions {
    private static string GetUrlWithDomainPrefix(string url) {
    if (url.StartsWith("/"))
    url = url.Substring(1);

    var domainPrefix = string.Format("http://{0}/", HttpContext.Current.Request.ServerVariables["HTTP_HOST"]);

    if (url.StartsWith(domainPrefix))
    return url;
    else
    return domainPrefix + url;
    }
    }

    The crash was caused by an error in line 29:

    node.ChildrenAsList.Count

    Which should actually be

    node.ChildrenAsList.Count()

    Just put the parentheses in and it works again :)

  • Mark Bennett 199 posts 375 karma points
    Jun 10, 2013 @ 13:46
    Mark Bennett
    0

    Jan,

    Thanks for posting this up as I had exactly the same issue.

    Cheers,
    Mark. 

Please Sign in or register to post replies

Write your reply to:

Draft