Copied to clipboard

Flag this post as spam?

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


  • Jonas Eriksson 930 posts 1825 karma points
    Feb 14, 2010 @ 19:55
    Jonas Eriksson
    0

    Hidden redirect (server transfer?) with Xslt

    Hi!

    I have a shortcut in the top navigation menu to "current issue", I use that to redirect the user to the correct page under another node (archive of issues). However it would be nice if the user could still be on the "current issue" url. 

    [home] [yada yada yada] [current issue] [archive of issues] [about us]

    I thought I could do that with a server transfer (inline .net-code), but it just did the same as response redirect. Dunno how to do this.

    The editor select the current issue from a global settings node, and that works fine. Here's the xslt 

    <xsl:template match="/">
    
        <xsl:variable name="siteRootNode" select="$currentPage/ancestor-or-self::node [@level=1]"/>
        <xsl:variable name="currentIssueNodeId" select="$siteRootNode/data [@alias='TeaserCurrentIssue']"/>
        <xsl:variable name="currentIssueUrl" select="umbraco.library:NiceUrl($currentIssueNodeId)"/>
        <xsl:value-of select="vb:Redirect($currentIssueUrl)"/>
    
    </xsl:template>
    
    <msxsl:script language="VB" implements-prefix="vb">
    <msxsl:assembly name="System.Web"/>
    <![CDATA[
        Public Function Redirect(url As String)
             ' Try 1
             'System.Web.HttpContext.Current.Response.Status = "301 Moved Permanently"
             'System.Web.HttpContext.Current.Response.AddHeader("Location", url)        
             ' Try 2
         'System.Web.HttpContext.Current.RewritePath(url)
             ' Try 3
         Server.Transfer(url)
             Return ""
        End Function
            ]]>
    </msxsl:script>
    

    Thanks

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 14, 2010 @ 21:30
    Jonas Eriksson
    0

    Changed to  System.Web.HttpContext.Current.Server.Transfer("/default.aspx?id=" & nodeId)

    but that killed the response, error 101.

    I think I'll just skip this method, doing some other better or worse workaround... Perhaps a template that prints bodytext 'n stuff from another node than current.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 14, 2010 @ 22:15
    Lee Kelleher
    0

    Hi Jonas,

    I might have misunderstood your question, but it sounds like you could use the "umbracoInternalRedirectId" property alias on your "current issue" page?

    http://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracointernalredirectid

    Let us know if I misunderstood... there's bound to be an easier solution for it! :-)

    Cheers, Lee.

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 15, 2010 @ 07:04
    Jonas Eriksson
    0

    Hi Lee

    Ah, yes, If I could use umbracointernalredirectid from xslt it would be the way to do it. The thing is that "current issue" is set from the main node as it is used for other stuff aswell. And we wish it to be set only at one place.

    Perhap I should use event handling to copy that setting, dunno.

    Cheers

    Jonas

  • Neil Campbell 58 posts 182 karma points
    Feb 15, 2010 @ 08:13
    Neil Campbell
    0

    You could use some javascript to do the redirect from within xslt, as below (also has fallback if js is disabled):

          <xsl:variable name="redirectNodeId">
             <xsl:for-each select="$currentPage/descendant::node [@nodeTypeAlias = 'blah']">
            <xsl:sort select="./data [@alias = 'articleDate']"  order="descending" />
            <xsl:if test="position() = 1">
                    <xsl:value-of select="./@id"/>
            </xsl:if>
             </xsl:for-each>
          </xsl:variable>
          <script language="javascript">
             document.location.href="<xsl:value-of select="umbraco.library:NiceUrl($redirectNodeId)"/>";
          </script>
          Please follow <a href="{umbraco.library:NiceUrl($redirectNodeId)}">this link</a>.

    Cheers,
    Neil

     

     

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 15, 2010 @ 09:34
    Jonas Eriksson
    0

    Thanks Neil, but I'd really like it to be moved by the server, and preferrably "under the hood" so the url is kept as it is.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 15, 2010 @ 09:45
    Lee Kelleher
    0

    @Jonas, I can't help but think that a redirect isn't the right way to go about this.  I'm keeping consideration that you said you'd like to keep the "current issue" URL the same ... so it sounds like you want to display the selected content (via the "TeaserCurrentIssue" property)?

    If so, then how about using GetXmlNodeById from umbraco.library?

    http://our.umbraco.org/wiki/reference/umbracolibrary/getxmlnodebyid

    Here's an example with XSLT:

    <xsl:template match="/">
        <xsl:variable name="siteRootNode" select="$currentPage/ancestor-or-self::node[@level=1]" />
        <xsl:variable name="currentIssueNodeId" select="$siteRootNode/data[@alias='TeaserCurrentIssue']" />
        <xsl:if test="string($currentIssueNodeId) != ''">
            <xsl:variable name="currentIssueNode" select="umbraco.library:GetXmlNodeById($currentIssueNodeId)"/>
            <xsl:if test="count($currentIssueNode/data) &gt; 0">
                <xsl:value-of select="$currentIssueNode/@nodeName" />
            </xsl:if>
        </xsl:if>
    </xsl:template>

    I added a couple of <xsl:if> conditions, just in case! ;-)

    Cheers, Lee.

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 15, 2010 @ 11:01
    Jonas Eriksson
    0

    Lee,

    yeah, I think I will - creating the content from that $currentIssueNode and adding all necessary content + creating an alternative template for that page.

    It will require that extra template though, and I really thought I could go a shortcut by server.transfer. How is umbracointernalredirectid doing its work internally? I'd perhaps look that up just for curiousity at least.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 15, 2010 @ 11:23
    Lee Kelleher
    0

    Hi Jonas,

    The way the "umbracoInternalRedirectId" property works is in the umbraco.requestHandler class.  If it is set, then the (Umbraco) request uses the node of that Id, rather than the page/node that is being requested.  So on the front-end, the context is still with the requested page.

    Take a look at the source-code on CodePlex, or crack open the umbraco.dll in Reflector if you want to know the inner workings.

    Cheers, Lee.

  • Murray Roke 503 posts 966 karma points c-trib
    May 27, 2010 @ 02:27
    Murray Roke
    0

    I know this doesn't exactly fit your problem, but I found it searching for a similar problem

    If "umbracoInternalRedirectId" is not for you (eg: you want to check a condition first)

    And you want to do a "Server.Transfer" in code behind, you can do something like this:

    Response.Write(umbraco.library.RenderTemplate(1234));
    Response.End();
Please Sign in or register to post replies

Write your reply to:

Draft