Solved

Session state - saving an object to memory, across pages

Posted on 2004-08-31
9
684 Views
Last Modified: 2010-05-18
Hi,

I am creating a framework for an e-commerce site, which is to be used and extended for our customers.

Now I would like people to be able to add things to their shopping carts, but then I would like these carts stored in memory, rather than on the SQL Server, for performance mainly.

If I have a dataset with 2 tables in it, how can I make this persist across the whole site, and how would I go about accessing a specific dataset?

Thanks
0
Comment
Question by:betocarranza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 9

Accepted Solution

by:
crescendo earned 125 total points
ID: 11942336
if your dataset is "ds", just do

   Session("myDataset") = ds

That will store the dataset in a session variable. Just do the opposite to use it on another page.

   Dim ds As Dataset = Session("myDataset")
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11942373
By the way, it's not particularly efficient if the dataset is large. You will have a dataset in a dataset variable, plus a copy in a session variable, thereby using twice as much memory as needed. Each user using the site has their own set of session variables, so on a busy site the dataset copies could eat up a lot of memory.
0
 
LVL 2

Expert Comment

by:netjkus
ID: 11942381
Basically, if you are on a webFarm , you cannot use Inproc. You are forced to use SQLServer or Stateserver. However storing anything other than the basic types like Objects etc will be too slow in SQLServer or Stateserver. Try to modify the logic so that you dont need the entire table in memory. If you are storing the cart for this session alone, you might have other options. But if you are stioring the cart till the user clears it, you have less choice.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:betocarranza
ID: 11942426
There are 2 kinds of users

1) Registered users, if they add something to a cart it stays there until they delete it or empty it (this case I would probably use SQL Server)

2) Unregister users, create a temporary cartID for them (a guid) and store this cart in memory. If they register, the cart will be saved, if not, they can still check it out or whatever, so it should remain in memory on the server.
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11942436
It's pretty common to store carts in cookies or SQL tables. Performance isn't generally an issue, because people only add items to their cart occasionally. Certainly not often enough! Most of their time is sent browsing and thinking. I use SQL tables personally, but cookies are just as valid. One benefit is that you can save carts across browser restarts, but you can't do that with session variables.
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11942463
I would use the same method whether the user is registered or not, to make code maintenance easier. Just save something to say that they need to register on checkout.
0
 
LVL 2

Author Comment

by:betocarranza
ID: 11942549
Okay, I will have a look at the cookies method, might be a lot easier than session variables!

How is the actual cart stored in a cookie though?
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11942910
Any way you can think of!

Try a string with ItemID and quantity values separated by a semicolon. Separate each item with CrLf. Its' easy enough to parse out. Save a separate string in the cookie as the shopper's ID or temporary ID.
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11942931
To set values in cookies use something like this:


                Response.Cookies("CartContents").Value = sCart

                Response.Cookies("CartContents").Expires = DateTime.Now.AddMonths(1)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question