Unable to access session variables from business object

Unable to access session variables from business object

Post by John Zull » Wed, 01 May 2002 02:41:43



I am having trouble accessing session variables from within a business
object created by the page class. The session variable is available in the
page class. I have tried the two lines from the example in MSDN article "A
Matter of Context"

http://www.veryComputer.com/
bdadotnetarchtopics.asp,

but when I look at the _context.session in the de* it is set to nothing
and the assignment to _value throws an error.
' get the request context
Dim _context As HttpContext = HttpContext.Current

 ' access the Session intrinsic
Dim _value As Object = _context.Session("TheValue")

Any help is appreciated,
John Zullo
(Remove spambgone. in email address to reply directly)

 
 
 

Unable to access session variables from business object

Post by William Reye » Wed, 01 May 2002 04:20:28


I am not sure if I udnerstand your problem fully but, I had a problem with
my session variables also. It turned out that I needed to go my services and
turn the Asp.NET State Server service on. Hope that helps.

William Reyes

Quote:> I am having trouble accessing session variables from within a business
> object created by the page class. The session variable is available in the
> page class. I have tried the two lines from the example in MSDN article "A
> Matter of Context"

http://www.veryComputer.com/
Quote:> bdadotnetarchtopics.asp,

> but when I look at the _context.session in the de* it is set to
nothing
> and the assignment to _value throws an error.
> ' get the request context
> Dim _context As HttpContext = HttpContext.Current

>  ' access the Session intrinsic
> Dim _value As Object = _context.Session("TheValue")

> Any help is appreciated,
> John Zullo
> (Remove spambgone. in email address to reply directly)


 
 
 

Unable to access session variables from business object

Post by John Zull » Wed, 01 May 2002 04:32:02


I don't think that is the problem, since the Session variables work in the
global.aspx and page classes. They just are not accessible in business
objects.


> I am not sure if I udnerstand your problem fully but, I had a problem with
> my session variables also. It turned out that I needed to go my services
and
> turn the Asp.NET State Server service on. Hope that helps.

> William Reyes


> > I am having trouble accessing session variables from within a business
> > object created by the page class. The session variable is available in
the
> > page class. I have tried the two lines from the example in MSDN article
"A
> > Matter of Context"

http://www.veryComputer.com/

- Show quoted text -

Quote:> > bdadotnetarchtopics.asp,

> > but when I look at the _context.session in the de* it is set to
> nothing
> > and the assignment to _value throws an error.
> > ' get the request context
> > Dim _context As HttpContext = HttpContext.Current

> >  ' access the Session intrinsic
> > Dim _value As Object = _context.Session("TheValue")

> > Any help is appreciated,
> > John Zullo
> > (Remove spambgone. in email address to reply directly)

 
 
 

Unable to access session variables from business object

Post by Marin » Wed, 01 May 2002 04:43:01


Is you business object a COM+ object in a Server app by any chance?


> I don't think that is the problem, since the Session variables work in the
> global.aspx and page classes. They just are not accessible in business
> objects.



> > I am not sure if I udnerstand your problem fully but, I had a problem
with
> > my session variables also. It turned out that I needed to go my services
> and
> > turn the Asp.NET State Server service on. Hope that helps.

> > William Reyes


> > > I am having trouble accessing session variables from within a business
> > > object created by the page class. The session variable is available in
> the
> > > page class. I have tried the two lines from the example in MSDN
article
> "A
> > > Matter of Context"

http://www.veryComputer.com/

- Show quoted text -

Quote:> > > bdadotnetarchtopics.asp,

> > > but when I look at the _context.session in the de* it is set to
> > nothing
> > > and the assignment to _value throws an error.
> > > ' get the request context
> > > Dim _context As HttpContext = HttpContext.Current

> > >  ' access the Session intrinsic
> > > Dim _value As Object = _context.Session("TheValue")

> > > Any help is appreciated,
> > > John Zullo
> > > (Remove spambgone. in email address to reply directly)

 
 
 

Unable to access session variables from business object

Post by John Zull » Wed, 01 May 2002 21:51:27


Maybe I am using the wrong terminlolgy. What I meant by business objects are
vb classes that are not pages or controls, just utility classes.


> Is you business object a COM+ object in a Server app by any chance?



> > I don't think that is the problem, since the Session variables work in
the
> > global.aspx and page classes. They just are not accessible in business
> > objects.



> > > I am not sure if I udnerstand your problem fully but, I had a problem
> with
> > > my session variables also. It turned out that I needed to go my
services
> > and
> > > turn the Asp.NET State Server service on. Hope that helps.

> > > William Reyes


> > > > I am having trouble accessing session variables from within a
business
> > > > object created by the page class. The session variable is available
in
> > the
> > > > page class. I have tried the two lines from the example in MSDN
> article
> > "A
> > > > Matter of Context"

http://www.veryComputer.com/

- Show quoted text -

Quote:> > > > bdadotnetarchtopics.asp,

> > > > but when I look at the _context.session in the de* it is set to
> > > nothing
> > > > and the assignment to _value throws an error.
> > > > ' get the request context
> > > > Dim _context As HttpContext = HttpContext.Current

> > > >  ' access the Session intrinsic
> > > > Dim _value As Object = _context.Session("TheValue")

> > > > Any help is appreciated,
> > > > John Zullo
> > > > (Remove spambgone. in email address to reply directly)

 
 
 

Unable to access session variables from business object

Post by Jim Stor » Thu, 02 May 2002 11:19:37


John,

I came across the same problem and haven't read the Microsoft article.
 My solution was to pass the context into my business object (class)
constructor which looks like this:

    Public Sub New(ByVal inContext As System.Web.HttpContext, _
                   ByVal inDBPath As String)
        ConnectionString =
ConfigurationSettings.AppSettings("ConnectionString")
        ClassContext = inContext
        sDBPath = inDBPath
    End Sub

This takes the context and the path of the database which I also had
trouble using in my class.  I create the class on my page as follows:

    Dim DBU As New DBUtil(Me.Context, Me.MapPath("..\DB"))

Hope this helps,

Jim.