Last post Feb 10, 2011 12:50 AM by raiye
Feb 02, 2011 11:29 PM|raiye|LINK
Hi, I need to implement the following feature for a shopping cart using profile:
1. User opens the site from Computer A and selects items which are added to the shopping cart. Now suppose the User logs in the same items should be displayed in the shopping cart as before he logged in. Now say he adds some more items to the shopping
cart and logs out, then the items he added newly should also be displayed in the shopping cart.
2. If the same User as in Step1 opens the site from Computer B and logs in there should be a different profile entry for him and he is not to be shown the items that were selected in the shopping cart in Step1.
I feel I need an implementation of the profile on per user+ computer basis for logged in Users. We have this kind of requirement for a B2B site where companies will have only one common login and it will be used by many Users to order items.
Thanks in advance for your help.
Feb 03, 2011 03:10 AM|KumarHarsh|LINK
we are discussing some of thing here,
i) cookie is not ideal
ii)I think also store ip address in db.
Feb 07, 2011 03:36 AM|Wenchao Zeng - MSFT|LINK
I would suggest using both
account name and a unique token stored in cookie to identify a user. Instead of using profile which is specified to a user account, I would suggest
creating a table in database to store the shopping carts. The table contains two columns mentioned above as key columns to identify a particular shopping cart.
To generate a unique token and store it in cookie, please refer to the code sample:
void Session_Start(object sender,
if (Request.Cookies["computerId"] ==
string computerId =
// Never expire cookie.
HttpCookie token =
new HttpCookie("computerId", computerId);
token.Expires = DateTime.Now.AddYears(100);
To get the token, please use the following code:
string computerId = Request.Cookies["computerId"].Value;
Hope this helps.
Feb 09, 2011 02:57 AM|raiye|LINK
Thanks for your help on this task. Since we wanted to give a shopping cart which supported both anonymous and authenticated users (where logins from different computers had to be considered as different shopping carts) after much research I have decided
to try and use the local storage feature which is a part of html5 and is supported from IE8 onwards and by other browsers.
This way my shopping cart should become browser independent also.
Feb 10, 2011 12:50 AM|raiye|LINK
Wanted to correct a part of my previous post so its not confusing. Local storage is stored in a different local database by each browser. So if user switches between say Chrome and FF the local storage values will differ.
Anyway in my case since I want to store the shopping cart on a per computer basis I feel this is the best option, since profile does not give this kind of flexibility.