Search code examples
asp.netbreadcrumbssitemappath

adding schema to SiteMapPath control cause 404 error


the following code would cause a 404 error. removing the code [itemtype="https://schema.org/BreadcrumbList"], then there is no error but using breadcrumb checker to validate the page, it is not recognized as breadcrumb. may i know which portion i am doing it wrong?

<asp:SiteMapPath ID="SiteMapPath1" itemtype="https://schema.org/BreadcrumbList" SkipLinkText="" runat="server" >
                    <NodeTemplate><a itemprop="item" href='<%#Eval("url") %>'><span itemprop="name"><%# Eval("title") %></span></a></NodeTemplate>
                </asp:SiteMapPath>

Solution

  • asp:SiteMapPath itself doesn't have itemtype property so the error (in fact 5xx not 404). So the code should be a little more elaborated. Something like this.

    <nav itemscope itemtype="http://schema.org/BreadcrumbList"><%--wrapper--%>
        <asp:SiteMapPath ID="SiteMapPath1" runat="server" PathSeparator=" : ">
            <NodeTemplate>
                <span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement"><%--wrapper for each breadcrumb--%>
                    <meta itemprop="position" content="<%#Container.ItemIndex+1 %>" /> <%--required by Google --%>
                    <a itemprop="item url" href='<%#Eval("url") %>'>
                       <span itemprop="name"><%# Eval("title") %></span>
                    </a>
                </span>
            </NodeTemplate>
        </asp:SiteMapPath>
    </nav>
    

    And this is generated HTML

    <nav itemscope itemtype="http://schema.org/BreadcrumbList">
        <span id="SiteMapPath1"><a href="#SiteMapPath1_SkipLink"><img alt="Skip Navigation Links" src="/WebResource.axd?d=Ybg6Za1EIYGIkin6VPiwIFL99ITKyu6RhGnxJcLOO8DP1KA0-cdYa4ltoyl-vbOlqsJF4S8oq8kKVCD1XukqME04tF9L2ZSF8XWKW9sT_mc1&amp;t=636668507379463780" width="0" height="0" style="border-width:0px;" /></a><span>
                <span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement">
                    <meta itemprop="position" content="1" />
                    <a itemprop="item url" href='/'><span itemprop="name">home</span></a></span>
            </span><span> : </span><span>
                <span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement">
                    <meta itemprop="position" content="2" />
                    <a itemprop="item url" href='my-page.aspx'><span itemprop="name">My Page</span></a></span>
            </span><a id="SiteMapPath1_SkipLink"></a></span>
    </nav>
    

    which passed Google Structured Data Test