Reading Session vars from a class in APP_CODE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yossimotro@gmail.com

    #1

    Reading Session vars from a class in APP_CODE

    Hi,

    I have a class in the APP_CODE folder which needs access to Session
    variables.
    When I try to read them I the following error:

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

    What should I do to make it work?
    Thanks.

  • Göran Andersson

    #2
    Re: Reading Session vars from a class in APP_CODE

    As you are saying that you are trying to read the session variables, I
    assume that you have already created them somewhere else in the
    application. Then session state is already enabled for the application,
    and the problem would therefore be that you are trying to access the
    session variables from a page that has enableSessionSt ate set to false.

    Check the properties of the page that is requested.

    yossimotro@gmai l.com wrote:[color=blue]
    > Hi,
    >
    > I have a class in the APP_CODE folder which needs access to Session
    > variables.
    > When I try to read them I the following error:
    >
    > Session state can only be used when enableSessionSt ate is set to true,
    > either in a configuration file or in the Page directive. Please also
    > make sure that System.Web.Sess ionStateModule or a custom session state
    > module is included in the <configuration> \<system.web>\< httpModules>
    > section in the application configuration.
    >
    > What should I do to make it work?
    > Thanks.
    >[/color]

    Comment

    • Bruno Alexandre

      #3
      Re: Reading Session vars from a class in APP_CODE

      you do not access sessions, or aplications variables directly in a class...

      what you can do however is sending the session object as a parameter, like:

      dim myUserName as string = session("userna me")

      myOwnClass.doSo mething(myUserN ame)


      in you class you have something like:

      Sub doDomething( ByVal strUsername as String)

      End Sub

      --

      Bruno Alexandre
      (a Portuguese in Københanv, Danmark)


      <yossimotro@gma il.com> escreveu na mensagem
      news:1148486776 .943678.69840@j 33g2000cwa.goog legroups.com...[color=blue]
      > Hi,
      >
      > I have a class in the APP_CODE folder which needs access to Session
      > variables.
      > When I try to read them I the following error:
      >
      > Session state can only be used when enableSessionSt ate is set to true,
      > either in a configuration file or in the Page directive. Please also
      > make sure that System.Web.Sess ionStateModule or a custom session state
      > module is included in the <configuration> \<system.web>\< httpModules>
      > section in the application configuration.
      >
      > What should I do to make it work?
      > Thanks.
      >[/color]


      Comment

      • yossimotro@gmail.com

        #4
        Re: Reading Session vars from a class in APP_CODE

        Hi folks,

        Thanks for the replies but I have found the problem.
        I was calling the session vars from the constructor of the class.
        I've changed that and it works fine.

        Thanks.

        Comment

        Working...