Reading Session vars from a class in APP_CODE

  • Thread starter Thread starter yossimotro
  • Start date Start date
Y

yossimotro

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 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.

What should I do to make it work?
Thanks.
 
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 enableSessionState set to false.

Check the properties of the page that is requested.
 
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("username")

myOwnClass.doSomething(myUserName)


in you class you have something like:

Sub doDomething( ByVal strUsername as String)

End Sub
 
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.
 
Back
Top