views:

63

answers:

4

we have a asp.net application which use session (in-proc) for single user across pages, now they want to keep the data (eg. a shopping cart) more persistent, even they leave the web app, means close the browser, next time they login use same id, they want the data back, any solution in ASP.NET?

If we save session in sql-server which I think is an option by microsoft, but I am not sure if it works even after user leave the app, or close the browser

+10  A: 

Session data is meant to only persist for the lifetime of that browser session.

The answer is to not save the data in session, save it in the database in ShoppingCart and ShoppingCartItem tables instead. These will persist as long as you want them to.

The ShoppingCart table would have a UserID column that is FK to your User table.

RedFilter
+1 - Persistence beyond the session is a Database. Saving sessions = bad.
glowcoder
+1  A: 

You'll need to construct a relational database and store the entries in there.

Granted, the Application scope is higher than Session, but it will only exist for the life of the application pool. It sounds like you're looking for permanent storage.

JustLoren
A: 

I've seen shopping cart system using cookies instead and some using both cookies and database.

Cookie only: The "official" size of a cookie is 4K

Cookie + database: Store a GUID in the cookie and use it as a reference in the database

But... I think that storing shopping cart in a cookie or a cookie/database is not very user friendly. I do prefer that the website forget my shopping cart if I leave. I'm annoyed when website store such information with my approval.

Pierre 303
A: 

You will need to use a database to mirror the data contained in the session, that way the data will persist long after the user logs off, if the application is restarted, or if the server is restarted. You could save the session object into sql-server as a binary object and serialize/deserialize when needed, but how do you know when to do the initial serialization? It's hard to tell when a user has logged off if they close the browser window.

Storing the session object as a single column might work in the interim, but in the long run you will probably want to come up with a proper relational design and store data in columns in tables, that way you can run queries and reports against the "work-in-progress" shopping carts (such as: how long do people let a shopping cart sit before finally checking out?).

As others have mentioned, cookies are another option but those exist on the client side, and if they decide to clear cookies (a lot of tech support people seem to give this advice as the first response when users complain about slow browsers), the shopping cart is lost.

FrustratedWithFormsDesigner