Reading Session vars from a class in APP_CODE

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

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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

Bruno Alexandre

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
 
Y

yossimotro

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top