Solved

asp.net web pages multidimensional session array

Posted on 2014-03-28
4
715 Views
Last Modified: 2014-03-28
Hello,

What I would like to do is store shopping cart items into session and store them in session array as such:

 
Session["cart"]
[0] => "1234"         - ItemID
          => "1"           - Qty
          => "10.00"    - Price
[1] => "1168"
          => "2"
          => "20.00"

Open in new window

0
Comment
Question by:CEL_IT
4 Comments
 
LVL 32

Accepted Solution

by:
Big Monty earned 250 total points
ID: 39961691
not sure if you're looking for a .NET solution or classic asp solution (since that's what you put the question in). I'm assuming .NET, so try this below:

string[,] myArray = new string[,] { { "1234", "1", "10.00" }, { "1168", "2", "20.00" };
Session("cart") = myArray;
0
 
LVL 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 250 total points
ID: 39961780
Just as easy as storing the array in the session, you can store in a cookie.  One of the problems with sessions is if the worker process over loads for some reason, the session restarts.  I have run into that before, it is not common, but does happen.  

On a slight tangent, it is best for your cart to store just the item_id and qty.  The price should be by a database look up and especially when submitting the final payment form.  Only submit item_id and qty and let the back end figure out the correct price, discount etc so you don't get spoofed.
0
 

Author Comment

by:CEL_IT
ID: 39961840
thanks Big monty,

Additionally, To retrieve from session:

var cartItems = (string[,])HttpContext.Current.Session["cart"];

Open in new window


To Count rows or columns:

int rows = cartItems .GetLength(0); 
int cols = cartItems .GetLength(1); 

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now