Copied to clipboard

Flag this post as spam?

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


  • SinkyPars 132 posts 175 karma points
    Aug 18, 2010 @ 11:02
    SinkyPars
    0

    Getting a session variable set in XSLT

    Hi guys,

    I have the folowing XSLT file which works great in getting back the session in other XSLT files:

    <xsl:variable name="dlang">
      <xsl:choose>
        <xsl:when test="umbraco.library:RequestQueryString('lang') != '' ">
            <xsl:value-of select="umbraco.library:RequestQueryString('lang')" />
        </xsl:when>
        <xsl:when test="umbraco.library:Session('lang') != ''">
            <xsl:value-of select="umbraco.library:Session('lang')" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$initlang" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="flang">
        <xsl:if test="$dlang != '' and $dlang != $initlang ">
            <xsl:value-of select="concat('_',$dlang)" />
        </xsl:if>
    </xsl:variable>

    <xsl:template name="setlang">
        <xsl:value-of select="umbraco.library:setSession('lang',$dlang) " />
    </xsl:template>

    <xsl:template match="/">
        <xsl:call-template name="setlang" />
        <xsl:value-of select = "$flang" />
    </xsl:template>

     

    However when I try and get the session in code eg:

    umbraco.library.Session("lang")

    Nothing is returned :-S

    Any help would be much appreciated.

    Thanks

     

    Scott

  • Dimitris Tsoukakis 33 posts 59 karma points
    Aug 18, 2010 @ 11:14
    Dimitris Tsoukakis
    0

    Hi Scott, 

    See if something is causing an app pool recycling. If this is happening your session vars are getting lost. I had a similar problem with memory caching. 

    Dimitris

  • SinkyPars 132 posts 175 karma points
    Aug 18, 2010 @ 11:25
    SinkyPars
    0

    Hi Dimitris,

    Its strange though that I can get the session in other XSL files :-S

    Maybe I am missing some using statements?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using umbraco.presentation.nodeFactory;
    using System.Data;
    using System.Collections;
    using System.Web.SessionState;

     

    And then all I do in the page load is - Response.Write(umbraco.library.Session("lang").ToString());

    But nothing is returned :(

    Thanks

     

    Scott

  • Tim 1193 posts 2655 karma points c-trib
    Aug 18, 2010 @ 12:35
    Tim
    0

    Hi Scott, is the page with this code opening in a popup windows, or is it switching from http to https?

  • SinkyPars 132 posts 175 karma points
    Aug 18, 2010 @ 12:52
    SinkyPars
    0

    Hi Tim,

    "Hi Scott, is the page with this code opening in a popup windows, or is it switching from http to https?" - Neither of these things are happening.

    Thanks

     

    Scott

  • Tom Maton 387 posts 659 karma points
    Aug 18, 2010 @ 16:45
    Tom Maton
    0

    Hi Scott,

    I believe you can just use the standard .NET Session method

    Session["lang"].ToString();

    As the reference to umbraco.library:SetSession() is really just used to set and retireve the session in the XSLT's

    Tom

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies