Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Scope Question

Status
Not open for further replies.

mit99mh

Programmer
Sep 24, 2002
246
GB
Is it possible using ASP.NET with VB to create a new object in a code behind file and give it Session Scope like JSP / Servlets allow?

Any help appreciated
 
You mean like

Dim obj as new Object
Session("Object") = obj
?

if so, then...yes.

D'Arcy
 
I was going to do something like this:

Dim employee as new Employee(1234)
Session("Employee") = employee

Each user would then see their employee data throughout the session.

If your code does this then thanks.
 
We did a similar thing in a former project, and it worked fine. However, objects in session do not keep their type (as so far as I've seen). By that I mean the session object won't recognize any attributes/methods in intellisense.

i.e.
my object has a LoadMe() function. If I instantiated the object, I could go
MyObject.LoadMe()

But if its in session, the .LoadMe() won't show up in intellisense, so I can either:
a) remember it and hard code it
Session("myObject").LoadMe()
or
b) cast the object within another object as soon as that page loads, and use the session as merely a transportation device
i.e.
page1:
Dim myObj as new object
Session("myObj") = myObj

Response.redirect("Page2.aspx")

page2:
Dim myObj as new object
myObj = Session("myObj")

If you use the session only for transportation, then you don't have objects sitting in memory using up resources.

hth

D'Arcy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top