Copied to clipboard

Flag this post as spam?

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


  • Giorgos Grispos 145 posts 179 karma points
    Sep 16, 2010 @ 09:52
    Giorgos Grispos
    0

    Check the Session lang in Materpage

    Hello,

    I am trying to have a simpe check session if else function using a piece of code in my master page.

    <% if (Request.Session["lang"] == "ENG"){ %>
              ENG
            <% }else{ %>
                GRE
            <% } %

    I am getting this error
    CS1061: 'System.Web.HttpRequest' does not contain a definition for 'Session' and no extension method 'Session' accepting a first argument of type 'System.Web.HttpRequest' could be found (are you missing a using directive or an assembly reference?)

    Any ideas guys?

    Cheers,
    Giorgos

  • Rik Helsen 670 posts 873 karma points
    Sep 16, 2010 @ 10:10
    Rik Helsen
    0

    We do this in xslt (I don't like inline code that much) and have created a dictionary item called "language" that returns a fixed string depening on what language site you are in:

     

    And the xslt code:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <xsl:choose>
    <xsl:when test="umbraco.library:GetDictionaryItem('Language') = 'nl'">
    <!-- Return Dutch stuff -->
    </xsl:when>
    <xsl:when test="umbraco.library:GetDictionaryItem('Language') = 'fr'">
    <!-- Return French stuff -->
    </xsl:when>
    <xsl:otherwise>
    <!-- Return English stuff -->
    </xsl:otherwise>
    </xsl:choose>


    </xsl:template>

    </xsl:stylesheet>
  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Sep 16, 2010 @ 10:12
    Michael Latouche
    0

    Hello Giorgos,

    You have to use Page.Session, or just Session would work also I think.

    Cheers,

     

    Michael.

  • Giorgos Grispos 145 posts 179 karma points
    Sep 16, 2010 @ 10:25
    Giorgos Grispos
    0

    Hello,

    Rik thanks for your answer, I know I can have this through xslt however I need to just test the other way to see if it works.

    Mike I tried both and I am getting an error

    Session state can only be used when enableSessionState is 
    set to true, either in a configuration file or in the Page directive. 
    Please also make sure that System.Web.SessionStateModule or a custom 
    session state module is included in the 
    <configuration>\<system.web>\<httpModules> section in 
    the application configuration.

    I can't find any of them in web.config and I am quite newbie to .net
    What should I need to change in config file? Any ideas

    Cheers,
    Giorgos

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Sep 16, 2010 @ 10:44
    Michael Latouche
    0

    Hello Giorgos,

    In the web.config file, you should have an entry like this:

    <system.web>


    <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="120" />

    As for the HttpModule, I don't think it is necessary because it should be included in the machine.config file. Anyway, if you need it, tou have to place it also under the system.web section of the web.config which then looks like this:

    <system.web>

    ...


    <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="120" />
    ...
    <httpModules>
    <add name="Session" type="System.Web.SessionState.SessionStateModule"/>

    </httpModules>
    ...

    </sysetm.web>

    Hope this helps.

     Cheers,

    Michael.

  • Giorgos Grispos 145 posts 179 karma points
    Sep 16, 2010 @ 11:18
    Giorgos Grispos
    0

    Thanks Michael,

    The default Umbraco installation has the sessionstate line you mention above. I don't really get where the problem is.
    I also tried the second way but nothing happened either. same error

    I might need to go for the xslt solution. Anyway thanks for your support.

    Cheers,
    Giorgos

  • Rik Helsen 670 posts 873 karma points
    Sep 16, 2010 @ 13:36
    Rik Helsen
    0

    A question that comes to mind, if you would use the session data, what would it return? the browser language or the language setting of the current site in Umbraco ?

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Sep 16, 2010 @ 13:41
    Michael Latouche
    0

    Hello Rik,

    As far as I know, it would return whatever value you have put in it. The session is not "pre-filled" with information, it is just a kind of dictionary wher you can store the information you want to be easily/rapidly available to all pages. But in order to retrieve a value from the session, you have to first put it in yourself.

    Cheers!

    Michael.

  • Giorgos Grispos 145 posts 179 karma points
    Sep 16, 2010 @ 13:53
    Giorgos Grispos
    0

    Hello both,

    What I am doing is to set the Session with either ENG or GRE values as the multilinual 1:1 example.

    Cheers
    Giorgos

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Sep 16, 2010 @ 14:11
    Michael Latouche
    0

    Hi Giorgos,

    Maybe a last try: again under the web.config <system.web> section, put the following line:

    <!-- Enable session state for all the pages in the Web application. -->
     <pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" smartNavigation="true" validateRequest="false" />

     If you already have a <pages> element, do not replace it but just make sure that you have the attribute enableSessionState="true" set.

    Good luck :-)

    Michael.

  • Giorgos Grispos 145 posts 179 karma points
    Sep 16, 2010 @ 14:39
    Giorgos Grispos
    0

    Hello,

    No luck again, I am sorry guys...
    There is a pages element where all ASPNETAJAX controls are there. I just added the attribute enableSessionState="true" with no luck.

    Cheers,
    Giorgos

Please Sign in or register to post replies

Write your reply to:

Draft