Copied to clipboard

Flag this post as spam?

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


  • Topic author was deleted

    Jan 11, 2015 @ 18:06

    Error loading razor version of Sitemap

    I am having the same problem as what's been described here before, however the mentioned fix doesn't work for me.

    Error loading Partial View script (file: ~/Views/MacroPartials/sitemapxml.cshtml)

    I am using 7.2.1 with the latest razor package of CultivSearchEngineSitemap.

    Does anyone have any ideas?

    It's a complete fresh install, with Cultive Dynamic Robots and the robots.txt editor packages installed.

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 11, 2015 @ 18:18
    Dennis Aaen
    0

    Hi Stephen,

    When you are in the partial macro for the CultivSearchEngineSitemap, then try to chage this line

    if (node.Level <= maxLevelForSiteMap && node.ChildrenAsList.Count > 0)

    To

     if (node.Level <= maxLevelForSiteMap && node.ChildrenAsList.Count() > 0)

    Hope this helps, solve your issue,

    /Dennis

  • Comment author was deleted

    Jan 11, 2015 @ 18:39

    As already mentioned, that fix doesn't appear to work.

    Partial View

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @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;
        }
    }

     

    Completely standard out of the box, with suggested fix, but still doesn't work. Using umbraco 7.2.1, CultivSearchEngineSitemap Razor 1.0.2, Robots.txt Editor and Cultiv Dynamic Robots.

     

    Template

    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
    <asp:content contentplaceholderid="ContentPlaceHolderDefault" runat="server"><?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">
            <umbraco:macro alias="sitemapxmlMacro" runat="server"></umbraco:macro>
        </urlset>
    </asp:content>

     

    I've even tried something like this as the template:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = null;
    }
    <?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">
    @Umbraco.RenderMacro("sitemapxmlMacro")
    </urlset>

    So I'm a bit confused as I say.

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 11, 2015 @ 20:07
    Dennis Aaen
    0

    Hi Stephen,

    Arh okay sorry did see not that. I have made some code that will works with Umbraco 7.2.

    I hope this can be a solution for you or at least a good starting point.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{

        var rootNode = CurrentPage.AncestorOrself(1);

    }
       
    @traverse(CurrentPage.AncestorOrSelf())
              
    @helper traverse(dynamic node){

        Response.ContentType = "text/xml";
        const int maxLevelForSiteMap = 100;
        var nodes = node.Children.Where("Visible");
           
            if (nodes.Any()) {

           
            foreach (var n in nodes)

            {

               
            var loc = "http://" + HttpContext.Current.Request.ServerVariables["HTTP_HOST"] + n.Url;

            <url>               
                <loc>@loc</loc>  
                <lastmod>@n.UpdateDate.ToString("yyyy-MM-dd")</lastmod>

                @if (node.HasValue("SearchEngineSitemapChangeFreq")){
                    <changefreq>@node.SearchEngineSitemapChangeFreq</changefreq>
                }

                @if (node.HasValue("SearchEngineSitemapPriority"){
                    <priority>@node.SearchEngineSitemapPriority</priority>
                }

            </url>

               
                @traverse(n)

           
            }

      
         }

    Hope this helps,

    /Dennis

  • Comment author was deleted

    Jan 12, 2015 @ 12:52

    I'm affraid that doesn't work either.

    It still comes up with the same error.

    Error loading Partial View script (file: ~/Views/MacroPartials/sitemapxml.cshtml)

    Has something major changed between like versions 7.1.4 and 7.2.1? or something?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 12, 2015 @ 14:42
    Dennis Aaen
    100

    Hi Stephen,

    Ar ok sorry the thing that gives problem is the if statement.

    So try this, I think it would be a good starting point.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{
        var rootNode = CurrentPage.AncestorOrself(1);
    }

    @traverse(CurrentPage.AncestorOrSelf())

    @helper traverse(dynamic node){
        Response.ContentType = "text/xml";
        const int maxLevelForSiteMap = 100;
        var nodes = node.Children.Where("Visible");
     
       
        if (nodes.Any())
        {
            foreach (var n in nodes)
            {
                var loc = "http://" + HttpContext.Current.Request.ServerVariables["HTTP_HOST"] + n.Url;
                <url>
                    <loc>@loc</loc>
                    <lastmod>@n.UpdateDate.ToString("yyyy-MM-dd")</lastmod>
                </url>
                @traverse(n)
            }
        }
    }

    Hope this helps,

    /Dennis

  • Comment author was deleted

    Jan 12, 2015 @ 15:25

    Dennis,

    Many thanks for that, it works, and with a little tweaking it now works as intended.

    One quick question I do have is how can I include the parent of my site nav?

    My Current Site structure

    Website Settings
    - EN (Homepage)
    - - About (Textpage)
    - - Contact (Textpage)
    - - Sitemap XML (Sitemap)
    - DE (Homepage)
    - - About (Textpage)
    - - Contact (Textpage)
    - - Sitemap XML (Sitemap)

    At the moment, when using

    @traverse(CurrentPage.AncestorOrSelf(2))

    It gets everything bellow EN, but not EN itself.

    What gets outputted:

    - - About (Textpage)
    - - Contact (Textpage)
    - - Sitemap XML (Sitemap)

    It's not including EN (Homepage) - How would I achieve this?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 12, 2015 @ 15:51
    Dennis Aaen
    0

    Hi Stephen,

    What if you change the:

    @traverse(CurrentPage.AncestorOrSelf(2))

    To

    @traverse(CurrentPage.AncestorOrSelf(1))

    or even without any digits in the AncestorOrSelf, does this include EN and DE folders.

    @traverse(CurrentPage.AncestorOrSelf())

    Hope this helps,

    /Dennis

  • Comment author was deleted

    Jan 12, 2015 @ 16:02

    Sorry, I should probablly of mentioned that each language will have it's own sitemapxml.

    So if I change from AncestorOrSelf(2) to AncestorOrSelf(1) - it does indeed include EN + Subpages & DE + Subpages.

    If I change AncestorOrSelf(2) to AncestorOrSelf() - then it doesnt display anything.

    So I need something in the middle of 1 & 2, haha. I need to start from level 2 (AncestorOrSelf(2)) but also include the parent/start node.

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 12, 2015 @ 16:05
    Dennis Aaen
    0

    Or try to see Jeavons comments on this post http://our.umbraco.org/forum/developers/razor/43525-SiteMap-for-Umbraco-V6x-MVC-Engine-, how he add homepage to the XML sitemap.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft