Still ok to use Session variables in ASP.NET mvc, or is there a better alternative for some things (like a cart)

Viewed 30066

I have a situation where I need access to a shopping cart over several pages. So, on the product page - create the cart an add some items On the cart checkout page - confirm the billing address On the cart checkout post - do a final check, add cart to DB and go off to payment

My question is, whats the best way to pass around the cart?

I have tried passing the Cart from page to postback and keeping all the values alive, however on some pages (the billing address confirmation page) this seems like a lot of hassle, all I want to check is the billing address and dont really want tons of HiddenFor() on the page to populate the cart back again

TempData[] is what I used for the product to checkout page, then wondered is it best to keep on setting TempData all the time when....

you could just use a session variable?

For some reason I read its not great practice to use Session, hence the question.

Thanks for your guidance, I can happy provide some code/more info if you deem it helpful.

7 Answers

In cart system the products that are added to cart are very important so using session is not good idea in my view. Using cookies and a temporary table in database is one of best Idea. We can store those data for forever or can clear after certain days.

Related