aspdotnetstorefront

AspDotNetStorefront add canonical url issue


I have no experience with the AspDotNetStorefront platform, so I need help setting up the package. The XML package code is below

 <?xml version="1.0" standalone="yes" ?>
<package version="2.1" displayname="BFGs canonical package" debug="false" includeentityhelper="false" allowengine="true">

    <query name="Products" rowElementName="Product">
        <sql>
            <![CDATA[
                SELECT ProductID, Name, SEName FROM Product WHERE ProductID = @ProductID
            ]]>
        </sql>
        <queryparam paramname="@ProductID" paramtype="request" requestparamname="ProductID" sqlDataType="int" defvalue="0"  validationpattern="^\d{1,10}$" />
    </query>
    <query name="Categories" rowElementName="Category">
        <sql>
            <![CDATA[
                SELECT CategoryID, Name, SEName FROM Category WHERE CategoryID = @CategoryID
            ]]>
        </sql>
        <queryparam paramname="@CategoryID" paramtype="request" requestparamname="CategoryID" sqlDataType="int" defvalue="0"  validationpattern="^\d{1,10}$" />
    </query>

    <PackageTransform>
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
          <xsl:output method="xml" omit-xml-declaration="yes" />

            <xsl:template match="/">

            <xsl:param name="site">https://www.tapestrymusic.com/</xsl:param>

            <xsl:param name="canonical">
            <xsl:choose>
            <xsl:when test="/root/Categories/Category/CategoryID > 0 and (/root/QueryString/pagenum > 1)"><xsl:value-of select="$site"/>c-<xsl:value-of select="/root/Categories/Category/CategoryID"/>-<xsl:value-of select="/root/Categories/Category/SEName"/>.aspx?pagenum=<xsl:value-of select="/root/QueryString/pagenum"/></xsl:when>
            <xsl:when test="/root/Categories/Category/CategoryID > 0"><xsl:value-of select="$site"/>c-<xsl:value-of select="/root/Categories/Category/CategoryID"/>-<xsl:value-of select="/root/Categories/Category/SEName"/>.aspx</xsl:when>
            <xsl:when test="/root/Products/Product/ProductID > 0"><xsl:value-of select="$site"/>p-<xsl:value-of select="/root/Products/Product/ProductID"/>-<xsl:value-of select="/root/Products/Product/SEName"/>.aspx</xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
            </xsl:param>

            <xsl:choose>
            <xsl:when test="$canonical != 0">
                <link rel="canonical" href="{$canonical}" />
            </xsl:when>
            <xsl:otherwise></xsl:otherwise>
            </xsl:choose>

            </xsl:template>0
            
        </xsl:stylesheet>
    </PackageTransform>
</package>

And I _Head.cshtml I add to like this

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

@Html.XmlPackage("Canonical")

<link rel="preconnect" href="https://fonts.googleapis.com">

But I get empty value,

<!--Xmlpackage 'Canonical' -->
<!--End of xmlpackage 'Canonical' -->

And I want to between these two comments to be something like <link rel="canonical" href="domain.com">


Solution

  • Answer is @Html.XmlPackage("canonical.xml.config")

    Just put this and It will show in head of pages