Link to home
Start Free TrialLog in
Avatar of rajivraj123
rajivraj123

asked on

Can I use Session object by adding asp.dll to references?

Hi..

I have some code from a guys here for training. I see the code that they have declared a Session object in VB! and have implemented a shoppng cart. they say they have some prob but i am not aware of the prob.

My query is can the Session object be created and used in VB?

thanx & regards,
rajiv
Avatar of mdougan
mdougan
Flag of United States of America image

Under .Net I think that there is a Session class, so, it's possibly .Net code.  But under VB6, no.  The code that you are seeing is probably ASP code, which is written in VB Script.  Looks very much like VB, but if it references a Session or Response objects then it is ASP.  
One other thought, there are objects in VB, such as MAPI objects that do have a Session object (I think that it's actually defined as a MAPISession though....)
Avatar of rkot2000
rkot2000

you can't create a session object in vb(session is created by iis), but you can use it. you need to add references to your vb project.
ASKER CERTIFIED SOLUTION
Avatar of rkot2000
rkot2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rajivraj123

ASKER

Thanx! :)

I have a class in VB with say 2 public variables. I create a object of this class, set the values of the variables and put in the session, as mentioned in those articles. Now, when I get the session variable in a ASP page, how can I type-cast the object from the session to the class I created in VB?


it's very bad idea to store an object with session:
full story :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnasdj00/html/asp1100.asp

Sessions and object references don't mix

If you plan on storing COM objects in the session object, you need to understand the performance implications. Most of the components created using Visual Basic 6.0 and even Visual C++ are single-threaded apartment (STA) components. The rules of COM dictate that the calls to an STA component ultimately need to execute on the same thread where the component was created.

Now, IIS maintains a pool of threads to service user requests. When an incoming request arrives, IIS picks the next free thread to process the request. Unfortunately, when you store an STA component in the session object, you have locked the session to a specific thread. Any further requests from that user session need to get routed to the original thread to satisfy the aforementioned rule. If the original thread is already busy processing another request, the new request will need to wait.

As an analogy, pretend on your first trip to the grocery store you went to aisle three for checking out. Now on every subsequent return to the grocery store you must always use aisle three, even when aisle three is crammed with shoppers and other aisles are open and available. Clearly, this can create problems.

p.s with asp you have late binding so you have something like this
dim x

set x=session("My_object")


Agreed, but if I am implemeting a shopping cart, where wil I store the user-specific data? Isnt session the only way out?`